Declarations and Initializations Questions
Practice Declarations and Initializations MCQs with answers and explanations. Page 1 of 2.
Category
C Programming
Topic
Declarations and Initializations
Page
1 / 2
Mode
Practice
Questions
Open any question to view the answer and explanation.
Identify the construct that is not a user-defined data type in C/C++ among the following: (1) struct book { char name[10]; float price; int pages; }; (2) long int l = 2.35; (3) enum day { Sun, Mon, Tue, Wed };
Open
View answer
C/C++ declarations: Is there any difference between the following function declarations—(1) extern int fun(); and (2) int fun();—when no function body is provided?
Open
View answer
C/C++ fundamentals: At what stage do we 'mention' (provide) the prototype of a function—defining, declaring, prototyping, or calling?
Open
View answer
C linkage example: In the program shown, where is variable 'a' declared and where is it defined? (extern int a; ... int a = 20;)
Open
View answer
C math library: Which statement correctly obtains the remainder of dividing 3.14 by 2.1 in floating-point arithmetic?
Open
View answer
C/C++ language basics: Is the statement 'extern int i;' a declaration or a definition?
Open
View answer
C math rounding: Which function call rounds 1.66 upward to 2.0 according to standard C/C++ library rules?
Open
View answer
C language linkage: Which types of linkages are recognized for identifiers in C—considering scope and visibility across translation units?
Open
View answer
C/C++ declarations: Which among the following lines are declarations (not definitions) — 1) extern int x; 2) float square(float x) { /* ... / } 3) double pow(double, double);
Open
View answer
C/C++ literals: By default, a real (floating) numeric literal such as 3.5 is treated as which type?
Open
View answer
C identifier rules: Which special symbol is allowed within a variable name according to standard C/C++ naming conventions?
Open
View answer
In C (16-bit Turbo C under DOS), what will this program output, considering 'extern' without a definition and assignment before any definition?
#include<stdio.h>
int main()
{
extern int i; // declaration only, no definition here
i = 20; // assignment requires a definition to exist at link time
printf("%d
", sizeof(i)); // sizeof uses the type, not the object
return 0;
}
Open
View answer
In C, what output is produced by the following enumeration and assignments (default enum starting at 0)?
#include<stdio.h>
int main()
{
enum status { pass, fail, atkt };
enum status stud1, stud2, stud3;
stud1 = pass; // 0
stud2 = atkt; // 2
stud3 = fail; // 1
printf("%d, %d, %d
", stud1, stud2, stud3);
return 0;
}
Open
View answer
C extern and definition order: what does this program print when a global is defined after main?
#include<stdio.h>
int main()
{
extern int a; // declaration
printf("%d
", a);
return 0;
}
int a = 20; // definition after main is valid
Open
View answer
In C, when a local variable shadows a global of the same name, which value prints?
#include<stdio.h>
int X = 40; // global
int main()
{
int X = 20; // local shadowing global
printf("%d
", X);
return 0;
}
Open
View answer
C prototype mismatch and argument promotions: what happens here (Turbo C style)?
#include<stdio.h>
int main()
{
extern int fun(float); // prototype says: takes float, returns int
int a;
a = fun(3.14); // call with float literal
printf("%d
", a);
return 0;
}
int fun(int aa) // actual definition: takes int, returns int
{
return (int)++aa;
}
Open
View answer
For-loop with scanf in the test expression: how many times does this loop execute (conceptually)?
#include<stdio.h>
int main()
{
int i = 5;
for ( ; scanf("%s", &i); printf("%d
", i) );
return 0;
}
Open
View answer
Array partial initialization in C: given only the first two elements, what prints?
#include<stdio.h>
int main()
{
int a[5] = {2, 3}; // remaining elements implicitly zero
printf("%d, %d, %d
", a[2], a[3], a[4]);
return 0;
}
Open
View answer
Turbo C (16-bit, DOS): sizes of near, far, and huge pointers when printed via sizeof on pointer variables
#include<stdio.h>
int main()
{
char *s1; // near pointer (default model)
char far *s2; // far pointer
char huge *s3; // huge pointer (normalized, same size as far)
printf("%d, %d, %d
", sizeof(s1), sizeof(s2), sizeof(s3));
return 0;
}
Open
View answer
Chained relational operators in C: how is this expression evaluated?
#include<stdio.h>
int main()
{
int x = 10, y = 20, z = 5, i;
i = x < y < z; // left-to-right evaluation with boolean 0/1
printf("%d
", i);
return 0;
}
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.