Complicated Declarations Questions
Practice Complicated Declarations MCQs with answers and explanations. Page 2 of 2.
Category
C Programming
Topic
Complicated Declarations
Page
2 / 2
Mode
Practice
Questions
Open any question to view the answer and explanation.
Pointer increments and self-referential structures in C (Turbo C under DOS): predict the output of this program.
#include<stdio.h>
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;
}
Open
View answer
Casting chain and sizeof result in Turbo C (DOS): what is printed here?
#include<stdio.h>
double i;
int main()
{
(int)(float)(char) i; // value unused; type chain matters
printf("%d", sizeof((int)(float)(char)i));
return 0;
}
Open
View answer
Turbo C (DOS): mix of near/far/huge with sizeof at different dereference depths — what is printed?
#include<stdio.h>
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;
}
Open
View answer
C on 16-bit DOS (Turbo C): what will this program print, and why does the cast chain not matter?
#include<stdio.h>
double i;
int main()
{
(int)(float)(char) i; // no effect on i or sizeof
printf("%d", sizeof(i));
return 0;
}
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.