514 views
1 votes
1 votes
What is the output of the program?

                int main()
                {
                    union a
                    {
                        int i;
                        char ch[2];
                    };
                    union a u;
                    u.ch[0] = 3;
                    u.ch[1] = 2;
                    printf("%d, %d, %d", u.ch[0], u.ch[1], u.i);
                    return 0;
                }

 

3 Answers

0 votes
0 votes
3 ,2 , garbage value
0 votes
0 votes
3 2 515

Bcz char take one byte and int take 4 byte .

Memory represation is lower byte store first

0000 0000 0000 0000 0000 0010 0000 0011=515

Related questions

237
views
0 answers
0 votes
Mayankprakash asked Jul 15, 2018
237 views
My doubt is very basic, I want to understand what is the use of signed and unsigned used with integer.?2.what does size of signed int (-128 to 127) signify?3how to big endian and little endian output problem in C.?Please suggestThanks
3.9k
views
2 answers
2 votes
Khushal Kumar asked Jul 4, 2017
3,901 views
Predict the output of following C programs1.#includeint main(){ char a = '\012'; printf("%d", a); return 0;}2.#includeint main(){ char a = '012'; printf( ... main(){ char a = '\012'; printf("%c", a); return 0;}
820
views
1 answers
3 votes
arpit.bagri asked Jul 26, 2023
820 views
What is the output of the code given below? #include <stdio.h> #include <string.h> union sample { int i; float f; char c; double d; char str[20]; }; int ... ; printf("Memory size occupied by sample : %d", sizeof(union sample)); return 0; }
236
views
0 answers
0 votes
Rajib Datta Roy asked Dec 26, 2023
236 views
#include <iostream>using namespace std;int main(){ float a,b,c; cout<<"Enter a="; cin>>a; b=a + (1-1); cout<<"a + (1-1)="<<b ... us a value .but after a= 1E-8 c gives us 0 can you explain how float data type is working here