Declarations and Initializations Questions
Practice Declarations and Initializations MCQs with answers and explanations. Page 2 of 2.
Category
C Programming
Topic
Declarations and Initializations
Page
2 / 2
Mode
Practice
Questions
Open any question to view the answer and explanation.
Partial structure initialization in C: unnamed members default to zero. What does this print?
#include<stdio.h>
int main()
{
struct emp
{
char name[20];
int age;
float sal;
};
struct emp e = {"Tiger"}; // only name given; others default-initialized
printf("%d, %f
", e.age, e.sal);
return 0;
}
Open
View answer
In C programming, consider variable shadowing and block scope. What will be the output of the following program?
#include<stdio.h>
int main()
{
int X = 40;
{
int X = 20;
printf("%d ", X);
}
printf("%d
", X);
return 0;
}
Choose the exact console output (spacing and order matter).
Open
View answer
In C (assume a typical little-endian system), what is the output of this program using a union to overlay int and char[2]?
#include<stdio.h>
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;
}
Select the exact numbers printed.
Open
View answer
In C structures, which of the following declarations is incorrect (identify the invalid one and explain why)?
1)
struct aa {
int a;
float b;
};
2)
struct aa {
int a;
float b;
struct aa var; // member is a complete object of the same type
};
3)
struct aa {
int a;
float b;
struct aa *var; // pointer to same type
};
Open
View answer
C typedef and extern syntax: which line is correct?
1) typedef long a; extern int a c;
2) typedef long a; extern a int c;
3) typedef long a; extern a c;
Open
View answer
Standard C expressions: which of the following operations is incorrect (produces a compile-time error) in ISO C?
Open
View answer
C structure syntax validation: which of the following structure definitions is correct as written?
1)
struct book {
char name[10];
float price;
int pages;
};
2)
struct aa {
char name[10];
float price;
int pages;
} // missing semicolon terminator
3)
struct aa {
char name[10];
float price;
int pages;
} // missing semicolon terminator
Open
View answer
C declarations: which of the following declarations is syntactically correct and defines an object?
Open
View answer
C literals: which option correctly represents a long double floating constant in standard C?
Open
View answer
C linkage and scope: if a global (external) variable is defined earlier in the same source file, must a function still declare it with extern before using it?
Open
View answer
C data model portability: does the size (number of bytes) of short int and long int vary across platforms and ABIs?
Open
View answer
C data types and ranges: evaluate the claim
“Range of float is from -2.25e+308 to +2.25e+308.”
Assume a typical C implementation targeting IEEE-754 formats unless explicitly stated otherwise.
Open
View answer
C floating types: if the numeric range of double is insufficient for a real number, can long double be used to extend range or precision?
Open
View answer
Legacy C environment (16-bit Turbo C under DOS): the stated range “double is from -1.7e-38 to +1.7e+38” — evaluate this claim.
Open
View answer
C type sizes (typical systems): “A float is 4 bytes wide, whereas a double is 8 bytes wide.” Assess this statement for common ABIs while acknowledging portability notes.
Open
View answer
C introspection: can you verify the sizes of short int and long int by using the sizeof operator in portable C code?
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.