What is the output of this program?
#include <stdio.h>
void main()
{
struct demo{
char * a;
int n;
};
struct demo p = {"hello", 2015};
struct demo q = p;
printf("%d", printf("%s",q.a));
}
Answer: C
Correct answer: hello5
The inner printf runs first, writing hello and returning 5 - the number of characters it wrote. The outer printf then prints that return value. So the output is hello5, in that order. (The assignment q = p copies the structure, including the pointer, so both point at the same string.)
Please log in or register to report this question.