Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Complicated Declarations Questions
Pointer increments and self-referential structures in C (Turbo C under DOS): predict the output of this program. #include
int main() { struct s1 { char *z; int i; struct s1 *p; }; static struct s1 a[] = { {"Nagpur", 1, a+1}, {"Chennai", 2, a+2}, {"Bangalore", 3, a } }; struct s1 ptr = a; printf("%s,", ++(ptr->z)); // advance z inside a[0] printf(" %s,", a[(++ptr)->i].z); // move ptr to a[1], index by its i printf(" %s", a[--(ptr->p->i)].z); // pre-decrement a[2].i then index return 0; }
Casting chain and sizeof result in Turbo C (DOS): what is printed here? #include
double i; int main() { (int)(float)(char) i; // value unused; type chain matters printf("%d", sizeof((int)(float)(char)i)); return 0; }
Turbo C (DOS): mix of near/far/huge with sizeof at different dereference depths — what is printed? #include
int main() { char huge *near *far *ptr1; char near *far huge ptr2; char far huge near ptr3; printf("%d, %d, %d ", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3)); return 0; }
C on 16-bit DOS (Turbo C): what will this program print, and why does the cast chain not matter? #include
double i; int main() { (int)(float)(char) i; // no effect on i or sizeof printf("%d", sizeof(i)); return 0; }
1
2