235k views
4 votes
What would be the output of the following program?

int main() {
struct message
{ int num;
char mess1[50];
char msg2[50] ;
} m ;
m. num = 1;
strcpy (m.msg1, "We had lot of homework." );
strcpy(m.msg2," Hope it is the last one);
/* assume that the strucure is located at address 2004*/
printf ("\\%u%u%u\\", &m.num, m.msgi, m3 m2 m.msg2 );
printf ("\\%d %s %s", m.num,m.msgi, m.msg2);
return 0;
}

User Mintaka
by
6.3k points

1 Answer

4 votes

Answer:

Output: 2004 2008 2058

Step-by-step explanation:

In the first printf command it will print the address of the variables num, msg1, msg2. And in the second printf command it will print the values of the variables num, msg1, msg2. As the address of the structure is 2004 And the size of the integer is 4 byte so size will increase with 4 bytes and the size of character is 1 byte so it will increase by 1*50= 50 bytes.

Hence, the output is 2004 2008 2058

User Shane Smiskol
by
6.8k points