Question Bank › Technical › C › MCQ
Other questions
Q301.Easy
What will be the output of the following C program?
#include<stdio.h>
#define y - -4
int main()
{
printf("%d", y);
return 0;
}- Compilation error
- -
- -4
- 4
Show answer & explanation
Answer: (D) 4Explanation: Step 1: The macro y is defined as - -4 (minus, space, minus, 4).
Step 2: In the printf, y is replaced by - -4.
Step 3: - -4 means negative of negative 4, which equals 4.
Step 4: So the output is 4.
Q302.Easy
What will be the output format of this C program?
#include<stdio.h>
int main()
{
char stamp[15] = "Current Date";
printf("%s\n", __DATE__ );
return 0;
}- Current Date
- Jul 15 2024
- Jul-2024-15
- 2024-15-Jul
Show answer & explanation
Answer: (B) Jul 15 2024Explanation: 1. __DATE__ is a predefined macro that expands to the date of compilation.
2. It is a string literal in the format "MMM DD YYYY" (e.g., Jul 15 2024).
3. The variable stamp is not used in the printf, so it does not affect the output.
4. Hence the printed format is like Jul 15 2024.
Q303.Easy
What will be the output of this C program?
#include<stdio.h>
#define n 3
int main()
{
int j;
j = n*n*n;
printf("%d",j);
return 0;
}- 27
- n is not declared
- No output
- Garbage value
Show answer & explanation
Answer: (A) 27Explanation: 1. #define n 3 is an object-like macro, so every n in the code is replaced by 3 before compilation.
2. The statement becomes j = 3*3*3;
3. 3*3*3 = 27.
4. printf prints 27.
Q304.Easy
What will be the output format of this C program?
#include<stdio.h>
int main()
{
char label[15] = "Current Time";
printf("%s\n",__TIME__);
return 0;
}- MM:HH:SS
- SS:MM:HH
- HH:MM:SS
- Current Time
Show answer & explanation
Answer: (C) HH:MM:SSExplanation: 1. __TIME__ is a predefined macro that expands to the time of compilation.
2. It is a string literal in the format "HH:MM:SS" (hours:minutes:seconds).
3. The variable label is not used in the printf, so it does not affect the output.
4. Hence the printed format is HH:MM:SS.
Q305.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
printf("Row :%d\n", __LINE__ );
return 0;
}- 3
- 6
- Compilation error
- 4
Show answer & explanation
Answer: (D) 4Explanation: 1. __LINE__ expands to the line number of the source file where it appears.
2. Count the lines: line 1 is #include, line 2 is int main(), line 3 is {, line 4 is the printf statement.
3. The printf containing __LINE__ is on line 4.
4. So __LINE__ becomes 4 and the output is: Row :4
Q306.Easy
What will be the output of the C program?
#include<stdio.h>
enum fruits {guava, papaya, banana};
int main()
{
printf("%d %d %d",banana,guava,papaya);
return 0;
}- 3 1 2
- 2 0 1
- 0 1 2
- 1 0 2
Show answer & explanation
Answer: (B) 2 0 1Explanation: 1) In an enum, the first member gets 0 by default: guava = 0.
2) Each next member increases by 1: papaya = 1, banana = 2.
3) printf prints banana, guava, papaya in that order.
4) So output is 2 0 1.
Q307.Easy
What will be the output of this C program (ignoring user input)?
#include<stdio.h>
int main()
{
enum colours { red, blue };
printf("%d %d", red, blue);
return 0;
}- Compilation error
- 1 2
- 0 1
- Runtime error
Show answer & explanation
Answer: (C) 0 1Explanation: 1. In an enum, the first enumerator gets value 0 by default.
2. Each following enumerator increases by 1.
3. So red = 0 and blue = 1.
4. printf prints '0 1'.
Q308.EasyAnswer under review
What will be the output of this C program?
#include<stdio.h>
static struct pupil
{
int x;
int y;
}pupil_var{};
int main()
{
printf("%d %d",pupil_var.x,pupil_var.y);
return 0;
}- Garbage values
- Improper structure variable declaration
- Compilation error
- 0 0
Show answer & explanation
Answer: (D) 0 0Explanation: 1. pupil_var is a static structure variable, so it has static storage duration.
2. Static objects are zero-initialized by default before main runs.
3. Hence both members x and y are 0.
4. The program prints 0 0.
Q309.Easy
What will be the output of this C program, assuming the user enters two integers (for example 4 and 6) when prompted?
#include<stdio.h>
int main()
{
int x, y;
printf("%d",(scanf("%d %d",&x,&y)));
return 0;
}- Compilation error
- 1
- 2
- none of the above
Show answer & explanation
Answer: (C) 2Explanation: 1) scanf returns the number of items successfully read.
2) The user supplies two integers, so both %d conversions succeed.
3) Therefore scanf returns 2.
4) printf prints that return value, giving output 2.
Q310.Easy
The preprocessor can trap simple errors like missing declarations, nested comments or mismatch of braces.
- True
- False
Show answer & explanation
Answer: (B) FalseExplanation: 1. The preprocessor only performs textual substitution and file inclusion.
2. It does not parse the C grammar, so it cannot detect missing declarations, nested comments or mismatched braces.
3. Such errors are detected later by the compiler.
4. Hence the statement is False.
Q311.Easy
What will be the output of the program?
#include<stdio.h>
#define SHOW( n ) printf("%d,", n )
int main()
{
int p = 5, q = 6, r = 7;
SHOW(p);
SHOW(q);
SHOW(r);
return 0;
}- 5, 6, 7,
- 5, 5, 5,
- 6, 6, 6,
- 7, 7, 7,
Show answer & explanation
Answer: (A) 5, 6, 7,Explanation: 1. SHOW(n) expands to printf("%d,", n).
2. SHOW(p) prints 5 followed by a comma.
3. SHOW(q) prints 6 followed by a comma.
4. SHOW(r) prints 7 followed by a comma.
5. Output is 5, 6, 7,.
Q312.Easy
After preprocessing is complete and the program is handed over to the compiler, the macros are no longer present in the expanded source code.
- True
- False
Show answer & explanation
Answer: (A) TrueExplanation: 1. The preprocessor runs before the compiler.
2. It replaces every macro invocation with its replacement text (macro expansion).
3. Once expansion is done, the macro definitions themselves are removed.
4. The compiler therefore sees only the expanded code with no macros left.
Q313.Easy
Will the program compile successfully?
#include<stdio.h>
int main()
{
#ifdef DEBUG
int n;
n = 15;
#else
int n;
n = 25;
#endif
printf("%d\n", n);
return 0;
}- Yes
- No
Show answer & explanation
Answer: (A) YesExplanation: Step 1: #ifdef DEBUG checks whether the macro DEBUG is defined; it is not defined anywhere.
Step 2: So the #ifdef block is skipped and the #else block is compiled.
Step 3: In the #else block, n is declared and assigned 25.
Step 4: printf prints 25. The program compiles and runs successfully.
Q314.Easy
Which of the following is a correctly formed object-like macro definition in C that defines a constant named SQUARE for the value 25?
- #define SQUARE (25);
- #define SQUARE 25
- #define SQUARE(25)
- #define SQUARE {25}
Show answer & explanation
Answer: (B) #define SQUARE 25Explanation: 1. An object-like macro has the form #define NAME value with no parentheses after the name.
2. Option '#define SQUARE (25);' has a stray semicolon which would become part of the replacement text.
3. '#define SQUARE(25)' is invalid because a function-like macro needs an identifier inside the parentheses.
4. '#define SQUARE {25}' would substitute braces, which is not a plain constant.
5. Hence '#define SQUARE 25' is the correct form.
Q315.Easy
At which stage does the line #include <stdio.h> get replaced by the actual contents of the file stdio.h?
- During editing
- During linking
- During execution
- During preprocessing
Show answer & explanation
Answer: (D) During preprocessingExplanation: 1) A C program passes through preprocessing, compilation, assembly and linking before execution.
2) The preprocessor handles all lines beginning with #, such as #include and #define.
3) When it sees #include <stdio.h>, it copies the entire text of stdio.h into the program at that point.
4) Linking only joins object files and libraries; execution happens much later.
5) So the replacement occurs during preprocessing.
Q316.Easy
Will the following program compile successfully?
#include <stdio.h>
int main() {
printf("Mumbai" "Pune\n");
return 0;
}- Yes
- No
Show answer & explanation
Answer: (A) YesExplanation: 1. Adjacent string literals are automatically concatenated by the compiler.
2. "Mumbai" "Pune\n" becomes "MumbaiPune\n".
3. This is valid C, so the program compiles and prints MumbaiPune.
4. Hence the answer is Yes.
Q317.Easy
In C, is it compulsory for a header file to have the .h extension?
- Yes, always
- No, any extension can be used
Show answer & explanation
Answer: (B) No, any extension can be usedExplanation: 1. The C preprocessor simply textually includes whatever file is named in #include.
2. It does not check or require the .h extension.
3. A file named myheader.txt or myheader.inc can be included just fine.
4. So the .h extension is a convention, not a requirement.
Q318.Easy
Macro calls and function calls work exactly similarly.
- True
- False
Show answer & explanation
Answer: (B) FalseExplanation: Step 1: A macro is a simple text substitution done by the preprocessor; e.g. SQUARE(4) becomes ((4)*(4)).
Step 2: A function is compiled once and called at runtime with proper argument evaluation.
Step 3: Because of textual substitution, macros can cause side-effect problems (like SQUARE(i++)) that functions do not.
Step 4: Hence macro calls and function calls do NOT work exactly similarly.
Q319.Easy
Is it mandatory for every C program to contain at least one preprocessor directive?
- True
- False
Show answer & explanation
Answer: (B) FalseExplanation: 1. A preprocessor directive is a line starting with #, such as #include or #define.
2. A valid C program can be written using only standard language constructs, e.g. int main(){return 0;}, with no # lines.
3. Therefore a preprocessor directive is not compulsory in every C program.
4. So the statement is False.
Q320.Easy
The preprocessor directives #ifdef ... #else ... #endif are used for conditional compilation.
- True
- False
Show answer & explanation
Answer: (A) TrueExplanation: 1. #ifdef checks whether a macro is defined.
2. Depending on the result, the block up to #else or #endif is compiled or skipped.
3. This is exactly what conditional compilation means.
4. So the statement is True.
Q321.EasyAnswer under review
What will be the output of the C program?
#include<stdio.h>
struct MatchScore
{
int wickets;
int runs;
}ms = {3, 287};
struct nation
{
char *name;
}nat = {"Australia"};
int main()
{
struct MatchScore mcopy = ms;
printf("%d %s %d", mcopy.runs, ms.wickets, nat.name);
return 0;
}- 287 3 Australia
- 287 3 garbage value
- Compilation error
- None of the above
Show answer & explanation
Answer: (A) 287 3 AustraliaExplanation: 1. The global struct ms is initialized with wickets=3 and runs=287.
2. The global struct nat is initialized with name pointing to "Australia".
3. In main, mcopy is a copy of ms, so mcopy.runs = 287.
4. printf prints mcopy.runs (287), ms.wickets (3), and nat.name (Australia).
5. Output: 287 3 Australia.
Q322.Easy
What will be the output of the C program?
#include<stdio.h>
int main()
{
struct item
{
int code;
char label[30];
};
struct item it[] = { {7, "item7"}, {8, "item8"}, {9, "item9"} };
printf("%d %s", it[2].code, (*(it+2)).label);
}- Compilation Error
- 7 item7
- 8 item8
- 9 item9
Show answer & explanation
Answer: (D) 9 item9Explanation: 1. it is an array of 3 structures: index 0 = {7,"item7"}, index 1 = {8,"item8"}, index 2 = {9,"item9"}.
2. it[2].code is the code of the third element = 9.
3. (*(it+2)) is the same as it[2], so .label gives "item9".
4. printf prints: 9 item9.
Q323.Easy
What will be the output of the C program?
#include<stdio.h>
struct
{
int roll;
float marks;
}student;
int main()
{
student.roll = 12;
student.marks = 8.73654;
printf("%d %.2f", student.roll, student.marks);
return 0;
}- 12 8.74
- 12 8.73654
- Compilation error
- None of the above
Show answer & explanation
Answer: (A) 12 8.74Explanation: 1. The structure variable student has roll = 12 and marks = 8.73654.
2. printf uses %d for roll, so it prints 12.
3. printf uses %.2f for marks, which rounds to 2 decimal places: 8.73654 becomes 8.74.
4. Output is: 12 8.74
Q324.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
struct point
{
int a, b, c, d;
};
struct point p = {7, 8, 9};
printf("%d %d %d %d", p.a, p.b, p.c, p.d);
return 0;
}- 7 8 9 garbage value
- 7 8 9 0
- 7 8 9 9
- None of the above
Show answer & explanation
Answer: (B) 7 8 9 0Explanation: 1) The struct is initialized with three values: a=7, b=8, c=9.
2) The remaining member d is not given a value.
3) In C, unlisted members of a partially initialized object are set to zero.
4) So d = 0 and output is 7 8 9 0.
Q325.Easy
What will be the output of the C program?
#include<stdio.h>
int main()
{
struct pioneer
{
char *name;
int born;
};
struct pioneer p1 = {"VikramSarabhai", 1919};
struct pioneer p2 = p1;
printf("%s %d", p2.name, p1.born);
return 0;
}- Compilation error
- Garbage value 1919
- VikramSarabhai 1919
- None of the above
Show answer & explanation
Answer: (C) VikramSarabhai 1919Explanation: 1. p1 is initialised with name pointing to "VikramSarabhai" and born = 1919.
2. p2 = p1 copies the whole structure (pointer value and int) member-wise.
3. p2.name points to the same string, so it prints "VikramSarabhai".
4. p1.born prints 1919. Output: "VikramSarabhai 1919".
Q326.Easy
In C, is it possible to declare an array whose elements are pointers to structures?
- True
- False
Show answer & explanation
Answer: (A) TrueExplanation: 1. A pointer to a structure can be declared, e.g. struct Student *p;
2. Arrays of any valid type can be declared, including pointer types.
3. So struct Student *arr[10]; is a valid array of 10 pointers to structures.
4. Hence the statement that it is not possible is false; it is possible.
Q327.Easy
What will be the output of the C program?
#include<stdio.h>
int main()
{
int 2_two = 25;
printf("%d",2_two);
return 0;
}- 2
- 25
- Runtime error
- Compilation error
Show answer & explanation
Answer: (D) Compilation errorExplanation: A variable name in C must begin with a letter or an underscore, never a digit.
Here the name '2_two' starts with the digit 2, which is invalid.
The compiler rejects the declaration as an invalid identifier.
Hence the program gives a compilation error.
Q328.Easy
What will be the output of the C program?
#include<stdio.h>
int main(){
int Marks = 42;
printf("%d",marks);
return 0;
}- no output
- 42
- Compilation error
- 0
Show answer & explanation
Answer: (C) Compilation errorExplanation: C is case-sensitive, so 'Marks' and 'marks' are two different identifiers.
Only 'Marks' is declared here; 'marks' is never declared.
The compiler cannot find a declaration for 'marks', so it reports an error.
Hence the program does not compile.
Q329.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
int val = 25;
{
int val = 60;
}
printf("%d",val);
return 0;
}- garbage value
- Compilation error
- 60
- 25
Show answer & explanation
Answer: (D) 25Explanation: 1. The outer 'val' is declared as 25 inside main.
2. The inner block declares a new 'val' = 60, which shadows the outer one only within that block.
3. After the inner block ends, the inner 'val' goes out of scope.
4. The printf uses the outer 'val', which is still 25.
5. Output is 25.
Q330.Easy
What will be the output of this program?
#include<stdio.h>
int main( )
{
int marks = 75 ;
{
int marks = 30 ;
printf( "%d " , marks);
}
printf( "%d\n" , marks);
return 0 ;
}- 75 75
- 30 75
- 30
- Error
Show answer & explanation
Answer: (B) 30 75Explanation: 1) The outer variable marks is set to 75.
2) Inside the inner block a new variable marks = 30 is created; it hides (shadows) the outer one.
3) The first printf prints the inner marks, so it prints 30.
4) After the block ends, the inner marks is destroyed; the second printf prints the outer marks, 75.
Output: 30 75.
Q331.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
int pqr = --15;
printf("%d",pqr);
return 0;
}- Runtime error
- Compilation error
- 14
- 15
Show answer & explanation
Answer: (B) Compilation errorExplanation: 1. The decrement operator '--' can only be applied to a modifiable variable, not to a constant literal.
2. Writing '--15' means trying to decrement the constant 15, which is not allowed.
3. The compiler rejects this initialization.
4. So the program produces a compilation error.
Q332.Easy
What will be the output of this C program?
#include<stdio.h>
int main(){
int _ = 6;
int __ = 6;
int ___ = _ + __;
printf("%d",___);
return 0;
}- Runtime error
- Compilation error
- 12
- Some Garbage value
Show answer & explanation
Answer: (C) 12Explanation: 1. In C, an identifier may consist only of letters, digits and underscores, and a name made only of underscores is valid.
2. So _ , __ and ___ are all legal variable names.
3. _ = 6 and __ = 6, so ___ = _ + __ = 6 + 6 = 12.
4. printf prints 12.
Q333.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
int low-val = 4;
int high-val = 12;
int avg = high-val + low-val / 2;
printf("%d",avg);
return 0;
}- 14
- 16
- Runtime error
- Compilation error
Show answer & explanation
Answer: (D) Compilation errorExplanation: 1. The variable names low-val and high-val contain the special character '-' (hyphen).
2. In C, a variable name may contain only letters, digits and underscore, and cannot contain '-'.
3. So the compiler rejects the declaration of low-val (and high-val) as invalid tokens.
4. Hence the program fails to compile, giving a compilation error.
Q334.Easy
What will be the output of the following C program?
#include<stdio.h>
int main(){
struct num
{
int num;
};
struct num key={25};
printf("%d",key.num);
return 0;
}- 0
- 25
- Garbage value
- Compilation error
Show answer & explanation
Answer: (B) 25Explanation: 1. A structure named num is defined, containing an integer member also named num.
2. A variable key of type struct num is declared and initialized with {25}, so key.num is set to 25.
3. The printf statement prints the value of key.num, which is 25.
4. The program compiles and runs successfully, outputting 25.
Q335.Easy
What will be the output of the following C program?
#include<stdio.h>
int x = -1;
int main(){
while(x++ == 1)
printf("loop");
return 0;
}- Prints Nothing
- loop
- loop loop
- loop loop loop
Show answer & explanation
Answer: (A) Prints NothingExplanation: 1. The global variable x is initialized to -1.
2. The condition x++ == 1 uses the post-increment operator: the value of x before increment (-1) is compared to 1.
3. Since -1 is not equal to 1, the condition is false.
4. The loop body is not executed, and the program terminates without printing anything.
5. (After the comparison, x becomes 0, but that does not affect the output.)
Q336.Easy
What will be the output of the following C program?
#include<stdio.h>
int main(){
int i = 4;
while(i == 4--)
printf("Loop ");
return 0;
}- Loop Loop Loop Loop
- Loop Loop Loop
- Compilation Error
- Prints Nothing
Show answer & explanation
Answer: (C) Compilation ErrorExplanation: 1. The expression 4-- attempts to apply the post-decrement operator to the constant 4.
2. In C, the decrement operator requires an lvalue (a modifiable object), but 4 is a constant literal.
3. Therefore, the compiler raises an error: "lvalue required as decrement operand".
4. The program fails to compile, so no output is produced.
Q337.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
while(!!5)
printf("Namaste");
return 0;
}- Namaste Namaste Namaste Namaste Namaste
- Namaste
- Infinite Loop
- Prints Nothing
Show answer & explanation
Answer: (C) Infinite LoopExplanation: 1. !!5 = !(!5) = !(0) = 1, which is always true.
2. The while condition never becomes false.
3. So printf("Namaste") runs forever, producing an infinite loop.
Q338.Easy
What will be the output of the C program?
#include<stdio.h>
int main(){
int n = 5;
while(--n > 0)
printf("Loop ");
return 0;
}- Loop Loop Loop Loop Loop Loop
- Loop Loop Loop Loop Loop
- Loop Loop Loop Loop
- Loop Loop Loop x Hard Luck
Show answer & explanation
Answer: (C) Loop Loop Loop LoopExplanation: 1) n starts at 5.
2) Condition --n > 0 pre-decrements first: n becomes 4, 4>0 true → print (1).
3) n becomes 3, true → print (2).
4) n becomes 2, true → print (3).
5) n becomes 1, true → print (4).
6) n becomes 0, 0>0 false → loop stops. Total 4 prints: 'Loop Loop Loop Loop'.
Q339.Easy
What will be the output of the C program?
#include<stdio.h>
int main()
{
char c = 0;
while(c == '0')
{
printf("Loop ");
break;
}
return 0;
}- Loop
- Compilation Error
- Runtime Error
- Prints Nothing x Hard Luck
Show answer & explanation
Answer: (D) Prints Nothing x Hard LuckExplanation: 1) c is declared as char and initialised with the integer 0, i.e. the null character (ASCII 0).
2) The character literal '0' has ASCII value 48, not 0.
3) The condition c == '0' becomes 0 == 48, which is false.
4) The while body is skipped entirely.
5) So the program prints nothing.
Q340.Easy
What will be the output of the following C program?
#include<stdio.h>
#define ZERO 0
int main()
{
while (ZERO == 0)
{
printf("Hello");
break;
}
return 0;
}- Prints Nothing
- Hello
- Hello Hello
- Compilation Error
Show answer & explanation
Answer: (B) HelloExplanation: 1. The macro ZERO is defined as 0, so the condition ZERO == 0 becomes 0 == 0, which is true.
2. The while loop body executes: it prints 'Hello' and then encounters break, which exits the loop immediately.
3. The loop is not repeated. Output: 'Hello'.
Q341.Easy
What will be the output of the following C program?
#include<stdio.h>
int main()
{
int x, y;
for(x = 0, y = 5; x < y; x++, y--)
printf("%d %d ", x, y);
return 0;
}- 0 1 2 5 4 3
- Compilation error
- 0 5 1 4 2 3
- Runtime error
Show answer & explanation
Answer: (C) 0 5 1 4 2 3Explanation: 1. Initialize x=0, y=5.
2. Condition x<y: 0<5 true → print '0 5 ', then x=1, y=4.
3. Condition 1<4 true → print '1 4 ', then x=2, y=3.
4. Condition 2<3 true → print '2 3 ', then x=3, y=2.
5. Condition 3<2 false → loop ends.
6. Output: '0 5 1 4 2 3 '.
Q342.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
int i;
for(i = 0; i>7; i+=3)
{
printf("for ");
}
return 0;
}- Nothing prints
- for
- for for for
- None of the above
Show answer & explanation
Answer: (A) Nothing printsExplanation: 1. The loop starts with i = 0.
2. The condition is i > 7, and 0 > 7 is false.
3. Since the condition fails on the very first check, the body never executes.
4. Therefore nothing is printed.
Q343.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
for(7;3;3)
printf("Namaste");
return 0;
}- Compilation error
- Program never ends
- Namaste
- None of the above
Show answer & explanation
Answer: (B) Program never endsExplanation: 1. In a for loop the middle part is the condition; any non-zero value is treated as true.
2. Here the condition is 3, which is non-zero, so it is always true.
3. The condition never becomes false, so the loop runs forever printing Namaste.
4. Hence the program never ends.
Q344.Easy
What will be the output of the following C program?
#include<stdio.h>
int main()
{
for(;;)
{
printf("%d ", 25);
}
return 0;
}- Compilation error
- 25
- Program never ends
- None of the above
Show answer & explanation
Answer: (C) Program never endsExplanation: 1) The for loop has no initialization, condition, or update: for(;;).
2) With no condition, the loop condition is treated as always true.
3) The body prints 25 repeatedly without any break statement.
4) Hence the program runs forever (infinite loop).
Q345.Easy
What will be the output of the following C program?
#include<stdio.h>
int main()
{
int p;
for(p = 0;p<=4;p++);
printf("%d", p);
return 0;
}- Compilation error
- 1 2 3 4
- 5
- 0 1 2 3 4
Show answer & explanation
Answer: (C) 5Explanation: 1. The for loop has an empty body (the semicolon right after it), so it only increments p.
2. p runs 0,1,2,3,4 — all satisfy p<=4 — then p becomes 5 and the condition fails.
3. After the loop, printf prints the final value of p, which is 5.
4. Output: 5
Q346.Easy
What will be the output of the following C program?
#include<stdio.h>
int main()
{
int m = 0;
for(m = 0;m == 0;m++)
{
printf("%d", m);
}
return 0;
}- 0
- Nothing prints
- 1
- None of the above
Show answer & explanation
Answer: (A) 0Explanation: 1. Initialise m=0; the condition m==0 is true.
2. Body prints the current value of m, which is 0.
3. Increment makes m=1; now m==0 is false, so the loop stops.
4. Only one iteration runs, printing 0.
Q347.Easy
What will be the output of the following C program?
#include<stdio.h>
#define forever for(;;)
int main()
{
printf("FINISHED");
forever;
return 0;
}- Compilation error
- Finished
- Program never ends
- None of the above
Show answer & explanation
Answer: (C) Program never endsExplanation: 1. The macro forever expands to for(;;), which is an infinite loop.
2. main first prints "FINISHED" once.
3. Control then enters the infinite for(;;) loop with no body and never exits.
4. So the program prints FINISHED and then keeps looping forever — it never ends.
Q348.Easy
What will be the output of this C program?
#include<stdio.h>
int y = 0;
int main(){
if(y == y)
printf("this is the if part");
else
printf("this is the else part");
return 0;
}- this is the if part
- this is the else part
- prints nothing
- Compile Time Error
Show answer & explanation
Answer: (A) this is the if partExplanation: 1. y is a global variable initialized to 0.
2. The condition y == y is 0 == 0, which is true.
3. So the statement inside the if block executes.
4. Output: this is the if part.
Q349.Easy
What will be the output of this C program?
#include<stdio.h>
int main(){
if("Please Enter")
printf("Welcome");
else
printf("Denied");
return 0;
}- Compilation Error
- Denied
- Welcome
- None of the above
Show answer & explanation
Answer: (C) WelcomeExplanation: 1. A string literal like "Please Enter" decays to the address of its first character.
2. That address is a non-zero pointer, which is treated as true in a condition.
3. So the if block executes.
4. Output is 'Welcome'.
Q350.Easy
What will be the output of this C program?
#include<stdio.h>
int main(){
int n;
if(TRUE)
printf("Condition holds");
else
printf("Condition fails");
return 0;
}- Condition holds
- Condition fails
- Compilation Error
- Runtime Error
Show answer & explanation
Answer: (C) Compilation ErrorExplanation: 1. C has no built-in keyword `TRUE` (only `true` exists in C99's stdbool.h, and even that needs the header).
2. `TRUE` is not declared anywhere, so the compiler reports an undeclared identifier.
3. Hence the program fails to compile.
Q351.EasyAnswer under review
Ravi is saving a photograph on his computer. Which of the following file extensions is typically used for binary files?
- .txt
- .c
- .jpg
- .dat
Show answer & explanation
Answer: (C) .jpgExplanation: 1. Text files store human-readable characters (e.g., .txt, .c source code).
2. Binary files store raw bytes that are not meant to be read as text.
3. A .jpg image is stored as raw binary image data.
4. Hence .jpg is the typical binary file extension among the options.
Q352.Easy
In C, files can be opened in various modes using fopen. Which of the following modes opens a file for writing in binary mode?
- "r"
- "rb"
- "w"
- "wb"
- "a"
Show answer & explanation
Answer: (D) "wb"Explanation: 1. The mode string's first character sets the operation: 'r' = read, 'w' = write, 'a' = append.
2. Adding 'b' makes the stream binary instead of text.
3. "r" and "rb" are read modes, "a" is append, "w" is text write.
4. Only "wb" combines write with binary, so it opens a file for binary writing.
Q353.EasyAnswer under review
Which of the following file-opening modes creates a new file if the specified file does not already exist?
- "r"
- "w"
- "a"
- "rb"
Show answer & explanation
Answer: (B) "w"Explanation: 1. Mode "r" opens an existing file for reading only; if the file is missing, fopen returns NULL and no file is created.
2. Mode "w" opens a file for writing; if the file does not exist, it is created, and if it exists, its contents are erased.
3. Mode "a" appends to a file and also creates it if missing, but among the given options the standard 'create/truncate' mode is "w".
4. Mode "rb" opens an existing binary file for reading; it does not create a file.
5. Hence the mode that creates a file if it does not exist is "w".
Q354.Easy
A C program opens an existing file "MARKS.TXT" with the statement: FILE *fp; fp = fopen("MARKS.TXT", "r+"); Which operations can be performed on this file through fp?- Reading only
- Writing only
- Appending only
- Both reading and writing
Show answer & explanation
Answer: (D) Both reading and writingExplanation: 1. The mode "r" opens a file for reading only.
2. The mode "w" opens (or creates) a file for writing only.
3. The mode "a" opens a file for appending only.
4. The mode "r+" opens an existing file for update, i.e., both reading and writing.
5. Hence with "r+" both reading and writing are allowed.
Q355.Easy
A C program (sample.c) is compiled and executed from the command line as:
cmd > sample Good Morning
/* sample.c */
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("%d %s", argc, argv[1]);
return 0;
}
What is the output?- 3 Good
- 2 Good
- Good Morning
- 3 Morning
Show answer & explanation
Answer: (A) 3 GoodExplanation: 1) Command line: sample Good Morning. The program name counts as one argument.
2) argc = number of arguments = 3 (sample, Good, Morning).
3) argv[0]="sample", argv[1]="Good", argv[2]="Morning".
4) printf prints argc then argv[1]: '3 Good'.
Q356.Easy
In a C union, must the data type of all its members be the same?
- True
- False
Show answer & explanation
Answer: (B) FalseExplanation: 1. A union is a user-defined type whose members share the same memory space.
2. The members may have different data types (e.g., int, float, char array).
3. Only the storage is shared; the types need not match.
4. Therefore the statement is False.
Q357.Easy
Which declaration correctly represents "an array of three pointers to chars" in C?
- char *ptr[3]();
- char *ptr[3];
- char (*ptr[3])();
- char ptr[3];
Show answer & explanation
Answer: (B) char *ptr[3];Explanation: 1. We need an array of 3 elements, so use `ptr[3]`.
2. Each element must be a pointer to char, so prefix with `char *`.
3. Combining gives `char *ptr[3];`.
4. The other options declare arrays of function pointers or plain chars.
Q358.Easy
What does the following declaration signify in C?
char *arr[10];
- arr is an array of 10 character pointers.
- arr is an array of function pointers.
- arr is an array of characters.
- arr is a pointer to an array of characters.
Show answer & explanation
Answer: (A) arr is an array of 10 character pointers.Explanation: 1) Operator precedence: [] binds tighter than *, so arr[10] is read first → arr is an array of 10 elements.
2) Each element is of type char * (pointer to char).
3) Therefore arr is an array of 10 character pointers.
Q359.Easy
Can a 2-Dimensional array be allocated dynamically in C?
- True
- False
Show answer & explanation
Answer: (A) TrueExplanation: 1) malloc/calloc return a pointer to a block of memory.
2) For a 2-D array we can allocate an array of row pointers, then allocate each row.
3) Alternatively a single block of rows*cols elements can be allocated and indexed manually.
4) Hence dynamic allocation of a 2-D array is possible: True.
Q360.Easy
What does the following declaration signify?
int (*pf)();
- pf is a pointer to function.
- pf is a function pointer.
- pf is a pointer to a function which returns int.
- pf is a function of pointer variable.
Show answer & explanation
Answer: (C) pf is a pointer to a function which returns int.Explanation: 1) The parentheses (*pf) make pf a pointer.
2) The following () show it points to a function.
3) The leading int is the function's return type.
4) So pf is a pointer to a function returning int.
Q361.Easy
What does the following declaration signify?
void *cmp();
- cmp is a pointer to a void type.
- cmp is a void type pointer variable.
- cmp is a function that returns a void pointer.
- cmp is a function that returns nothing.
Show answer & explanation
Answer: (C) cmp is a function that returns a void pointer.Explanation: 1) The () after cmp shows cmp is a function.
2) The * before cmp belongs to the return type, so the function returns a pointer.
3) The pointed type is void, so it returns a void pointer (generic pointer).
4) Hence cmp is a function returning a void pointer.
Q362.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
int a = 245;
const int b = a;
printf("%d\n", b);
return 0;
}- 245
- Garbage value
- Compilation error
- 0
Show answer & explanation
Answer: (A) 245Explanation: Step 1: int a = 245; declares integer a and sets it to 245.
Step 2: const int b = a; declares a const int b and initializes it with the value of a, so b = 245 (initializing a const at declaration is allowed).
Step 3: printf("%d\n", b); prints the value of b, which is 245.
So the output is 245.
Q363.Easy
What will be the output of this program?
#include <stdio.h>
int main() {
const c = -11;
const int d = 34;
printf("%d, %d\n", c, d);
return 0;
}- Error
- -11, 34
- 11, 34
- None of these
Show answer & explanation
Answer: (B) -11, 34Explanation: 1. const c = -11; declares c as a constant (implicitly int) with value -11.
2. const int d = 34; declares d as a constant int with value 34.
3. printf prints c and d in order, giving -11, 34.
4. Hence the output is -11, 34.
Q364.Easy
Point out the error in the program:
#include <stdio.h>
int main() {
const int y;
y = 256;
printf("%d\n", y);
return 0;
}- Error: unknown data type const int
- Error: const variable must be initialised when declared
- Error: stack overflow in y
- No error
Show answer & explanation
Answer: (B) Error: const variable must be initialised when declaredExplanation: Step 1: A const variable cannot be modified after its declaration.
Step 2: Here y is declared without an initializer.
Step 3: The later assignment y = 256 attempts to modify the const object.
Step 4: The compiler reports an error: assignment of read-only variable.
Q365.Easy
What will be the output of the program?
#include<stdio.h>
int fetch();
int main()
{
const int y = fetch();
printf("%d", y);
return 0;
}
int fetch()
{
return 35;
}- Garbage value
- Error
- 35
- 0
Show answer & explanation
Answer: (C) 35Explanation: Step 1: int fetch(); is a prototype for a function returning int with no parameters.
Step 2: const int y = fetch(); initializes the constant y with the return value of fetch(), which is 35. Initializing a const at declaration is allowed.
Step 3: printf("%d", y) prints 35.
Q366.Easy
What will be the output of the program?
#include<stdio.h>
int main()
{
const int k = 4;
printf("%d\n", k++);
return 0;
}- 4
- 5
- No output
- Error: cannot modify a const object
Show answer & explanation
Answer: (D) Error: cannot modify a const objectExplanation: Step 1: const int k = 4; declares k as a constant integer.
Step 2: k++ tries to increment k, i.e. it attempts to modify a const object.
Step 3: The compiler raises an error 'cannot modify a const object', so the program does not compile and produces no output.
Q367.Easy
What will be the output of the program?
#include<stdio.h>
int main()
{
int k, num = 45;
k = (num < 20) ? 300 : 400;
printf("%d\n", num);
return 0;
}- 400
- 45
- 300
- 700
Show answer & explanation
Answer: (B) 45Explanation: Step 1: num is initialized to 45.
Step 2: The ternary condition (num < 20) is (45 < 20), which is false, so k gets 400.
Step 3: The printf statement prints num, not k. num is still 45.
Hence the output is 45.
Q368.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
int a = 7, b = 15;
if(!(!a) && a)
printf("a = %d\n", a);
else
printf("b = %d\n", b);
return 0;
}- b = 15
- a = 0
- a = 7
- a = 1
Show answer & explanation
Answer: (C) a = 7Explanation: 1) a = 7, so !a = 0.
2) !(!a) = !0 = 1.
3) Condition becomes (1 && 7) which is true (non-zero).
4) So the if-branch runs and prints 'a = 7'.
Q369.Easy
How many times will the while loop execute in the following C program? (Assume int is 4 bytes wide.)
#include <stdio.h>
int main()
{
int k = 1;
while (k <= 200)
{
printf("%c %d\n", k, k);
k++;
}
return 0;
}- Infinite times
- 200 times
- 201 times
- 199 times
Show answer & explanation
Answer: (B) 200 timesExplanation: Step 1: k starts at 1.
Step 2: The loop runs while k <= 200, i.e. for k = 1, 2, 3, ..., 200.
Step 3: That is exactly 200 iterations.
Step 4: The size of int does not affect the loop count here.
Q370.Easy
What will be the output of the program?
#include <stdio.h>
int main()
{
char name[] = "Delhi";
int marks = 4;
printf(marks > 20 ? "Pass\n" : "%s\n", name);
return 0;
}- Delhi
- Pass
- Error
- None of the above
Show answer & explanation
Answer: (A) DelhiExplanation: Step 1: name holds "Delhi" and marks holds 4.
Step 2: The condition marks > 20 is 4 > 20, which is false.
Step 3: So the ternary operator selects the else branch "%s\n".
Step 4: printf then prints the string name, i.e. Delhi.
Q371.Easy
What will be the output of the program?
#include<stdio.h>
int main()
{
int a = 7;
float b = 7.0;
if (a == b)
printf("a and b are equal");
else
printf("a and b are not equal");
return 0;
}- a and b are equal
- a and b are not equal
- Unpredictable
- No output
Show answer & explanation
Answer: (A) a and b are equalExplanation: Step 1: int a = 7; stores integer 7.
Step 2: float b = 7.0; stores floating value 7.0.
Step 3: In if(a == b), the int a is promoted to float, so 7.0 == 7.0 is true.
Step 4: Hence it prints 'a and b are equal'.
Q372.Easy
Identify the error, if any, in this C program:
#include <stdio.h>
int main()
{
int choice = 2;
switch (choice)
{
case 2:
printf("Start");
break;
case 3 * 2 + 1:
printf("Stop");
break;
}
return 0;
}- Error: case 3 * 2 + 1 is not allowed
- Error: no default case specified
- Error: in switch statement
- No error
Show answer & explanation
Answer: (D) No errorExplanation: 1) A case label must be a constant integer expression, not necessarily a plain literal.
2) 3 * 2 + 1 is a constant expression that evaluates to 7 at compile time, so it is valid.
3) choice is 2, which matches case 2.
4) So "Start" is printed and break exits the switch.
5) A default case is optional, so its absence is not an error.
Q373.Easy
What will be the output of the following C program?
#include<stdio.h>
int main(){
int val = - -5;
printf("val = %d", val);
return 0;
}- Runtime error
- Compilation error
- -5
- 5
Show answer & explanation
Answer: (D) 5Explanation: The expression - -5 consists of two unary minus operators applied to 5. The first minus negates 5 to -5, and the second minus negates -5 to 5. So val becomes 5. The program compiles and runs without error, printing 'val = 5'.
Q374.Easy
Which of the following operations is INCORRECT in C?
- int i = 35; i = i % 5;
- short int j = 255; j = j;
- long int k = 365L; k = k;
- float a = 3.14; a = a % 3;
Show answer & explanation
Answer: (D) float a = 3.14; a = a % 3;Explanation: 1. The modulus operator `%` can only be applied to integer types (int, char, short, long, etc.).
2. In option A, `i % 5` is valid because `i` is an int.
3. Options B and C are simple assignments, which are valid.
4. Option D attempts `a % 3` where `a` is a float, which is illegal; the compiler will give an error like "Illegal use of floating point".
5. Therefore, the incorrect operation is D.
Q375.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
25;
printf("%d", 25);
}- Compilation Error
- 25
- Runtime error
- No output
Show answer & explanation
Answer: (B) 25Explanation: 1. The statement '25;' is a valid expression statement (value discarded), not a syntax error.
2. So the program compiles fine.
3. printf then prints the integer 25.
4. Output is 25.
Q376.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
int k = 5;
k++;
k * k;
printf("%d\n", k);
return 0;
}- 36
- 25
- 5
- 6
Show answer & explanation
Answer: (D) 6Explanation: 1. k starts at 5.
2. k++ increments k to 6 (the statement alone stores the result).
3. The line 'k * k;' computes a value but does not store it, so k stays 6.
4. printf prints 6.
Q377.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
void value=10;
printf("%v", value);
return 0;
}- Compilation error
- 10
- Garbage value
- 0
Show answer & explanation
Answer: (A) Compilation errorExplanation: 1. void is an incomplete type; you cannot declare a variable of type void.
2. The line 'void value=10;' is invalid, so the compiler reports an error.
3. Also %v is not a valid printf conversion specifier.
4. Hence the program does not compile.
Q378.Easy
What will be the output of the C program?
#include<stdio.h>
int main()
{
float a = 2.75;
double b = 2.75;
printf("%f %f",a, b);
return 0;
}- Runtime error
- Compilation error
- 2.750000 2.750000
- 2.750000 2.750000f
Show answer & explanation
Answer: (C) 2.750000 2.750000Explanation: 1) float a = 2.75; and double b = 2.75; are both valid real types.
2) %f is the format specifier for float and also works for double (double is promoted).
3) printf prints each with 6 decimal places: 2.750000 and 2.750000.
4) Output: 2.750000 2.750000.
Q379.Easy
What will be the output of the C program?
#include<stdio.h>
int main()
{
typedef int marks;
marks m1 = 42;
printf("%d", m1);
return 0;
}- Compilation error
- 42
- 1
- Runtime error
Show answer & explanation
Answer: (B) 42Explanation: 1) typedef int marks; creates an alias marks for int.
2) marks m1 = 42; declares m1 as int and initializes it to 42.
3) printf("%d", m1) prints 42.
4) No error occurs.
Q380.Easy
Which set lists the real (floating-point) data types available in C?
- float, double
- short int, double, long int
- float, double, long double
- double, long int, float
Show answer & explanation
Answer: (C) float, double, long doubleExplanation: 1. Real data types store numbers with fractional parts.
2. In C these are float, double and long double.
3. short int and long int are integer types, not real types.
4. Hence the complete correct set is float, double, long double.
Q381.Easy
Is the following statement a declaration or a definition?
extern int count;
- Declaration
- Definition
- Function
- Error
Show answer & explanation
Answer: (A) DeclarationExplanation: The keyword extern tells the compiler that the variable 'count' exists somewhere else (in another file or later in the program).
It does not reserve any memory for the variable here.
A statement that only announces the type/name without allocating storage is a declaration.
Hence 'extern int count;' is a declaration.
Q382.Easy
In C, a structure variable declared inside a function without any storage class specifier has which storage class by default?
- auto
- static
- extern
- register
Show answer & explanation
Answer: (A) autoExplanation: 1. A variable declared inside a function (block scope) with no storage class specifier defaults to auto.
2. This applies to structure variables too.
3. auto variables have automatic storage duration (created on entry, destroyed on exit).
4. So the default storage class is auto.
Q383.Easy
A long double can be used if the range of a double is not enough to accommodate a real number.
- True
- False
Show answer & explanation
Answer: (A) TrueExplanation: 1) double typically occupies 8 bytes.
2) long double typically occupies 10 bytes (or more), giving a larger range and precision.
3) So when double's range is insufficient, long double can be used.
4) Hence the statement is True.
Q384.Easy
Which of the following statements correctly obtains the remainder after dividing 7.5 by 2.4 in C?
- rem = 7.5 % 2.4;
- rem = modf(7.5, 2.4);
- rem = fmod(7.5, 2.4);
- Remainder cannot be obtained in floating point division.
Show answer & explanation
Answer: (C) rem = fmod(7.5, 2.4);Explanation: 1) The % operator works only on integers in C, so 7.5 % 2.4 is invalid.
2) modf() splits a number into integer and fractional parts; it does not compute a remainder.
3) fmod(x, y) from <math.h> returns the floating-point remainder of x/y.
4) fmod(7.5, 2.4) = 7.5 - 2*2.4 = 2.7, so fmod is the correct choice.
Q385.Easy
When do we write the prototype of a function in C?
- While defining the function
- While declaring the function
- While prototyping the function
- While calling the function
Show answer & explanation
Answer: (B) While declaring the functionExplanation: 1) A function prototype gives the function's name, parameter types and return type but no body.
2) It is written at the time of declaring the function, before it is used.
3) The definition contains the actual body of the function.
Hence the prototype is written while declaring the function.
Q386.Easy
In C, a float is typically 4 bytes wide, whereas a double is typically 8 bytes wide.
- True
- False
Show answer & explanation
Answer: (A) TrueExplanation: 1. The C standard does not fix the size, but on most common platforms (including Turbo C and modern compilers), `float` occupies 4 bytes.
2. `double` usually occupies 8 bytes, providing more precision.
3. Hence, the statement is generally true.
Q387.Easy
The size of a short integer and a long integer can differ from one platform to another in C.
- True
- False
Show answer & explanation
Answer: (A) TrueExplanation: 1. In C, the standard only guarantees minimum ranges for types, not fixed byte sizes.
2. The actual size depends on the compiler and the system architecture (e.g., 16-bit vs 32-bit vs 64-bit).
3. For example, int may be 2 bytes on one platform and 4 bytes on another.
4. Hence short and long integer sizes can vary across platforms, so the statement is True.
Q388.Easy
What is the output of the program?
#include<stdio.h>
int main( )
{
int a[ 5 ] = { 7 , 4 };
printf( "%d, %d, %d\n" , a[ 2 ], a[ 3 ], a[ 4 ]);
return 0;
}- Garbage Values
- 7, 4, 4
- 4, 7, 7
- 0, 0, 0
Show answer & explanation
Answer: (D) 0, 0, 0Explanation: 1. The array a has 5 elements but only two are given: a[0]=7, a[1]=4.
2. In C, when an automatic (local) array is partially initialized, the remaining elements are set to 0.
3. So a[2]=0, a[3]=0, a[4]=0.
4. The printf therefore prints 0, 0, 0.
Q389.Easy
Which of the following correctly represents a long double constant in C?
- 9.25
- 9.25L
- 9.25f
- 9.25LD
Show answer & explanation
Answer: (B) 9.25LExplanation: 1. A floating constant's type is set by its suffix.
2. No suffix means type double (9.25).
3. Suffix f or F means float (9.25f).
4. Suffix l or L means long double, so 9.25L is correct.
5. 'LD' is not a valid suffix.
Q390.Easy
Which of the following special characters is allowed in a C variable name?
- * (asterisk)
- | (pipe)
- - (hyphen)
- _ (underscore)
Show answer & explanation
Answer: (D) _ (underscore)Explanation: 1. A C variable name may contain letters (A-Z, a-z), digits (0-9) and the underscore character.
2. It must not begin with a digit.
3. Symbols like *, | and - are operators, not allowed in names.
4. So only the underscore is permitted, e.g. student_marks or _count.
Q391.Easy
Consider the declaration: typedef enum status { pending, approved, rejected } result; What does 'result' represent here?- It is a typedef (new name) for enum status.
- It is a variable of type enum status.
- The statement is erroneous.
- It is a structure.
Show answer & explanation
Answer: (A) It is a typedef (new name) for enum status.Explanation: 1. The keyword typedef creates an alias for an existing type.
2. Here the existing type is enum status.
3. So result becomes another name for enum status.
4. No variable is created by this statement; you would later write result r; to declare a variable.
5. Therefore result is a typedef for enum status.
Q392.Easy
Is it true that a function can have multiple declarations but only one definition?
- Yes
- No
Show answer & explanation
Answer: (A) YesExplanation: 1) A declaration only tells the compiler the function's name, return type and parameters; it can be repeated.
2) A definition provides the actual body and may appear only once.
3) All declarations must be identical to be valid.
4) Hence the statement is true.
Q393.Easy
What will be the output of the program?
#include<stdio.h>
int marks=75;
int main()
{
int marks=30;
printf("%d\n", marks);
return 0;
}- 30
- 75
- Error
- No Output
Show answer & explanation
Answer: (A) 30Explanation: 1. A global variable marks is declared with value 75.
2. Inside main, a local variable marks is declared with value 30.
3. When a local and global variable share a name, the local variable shadows the global one.
4. printf prints the local marks, so the output is 30.
Q394.Easy
In C, by default a real (floating-point) number written without any suffix is treated as a
- float
- double
- long double
- far double
Show answer & explanation
Answer: (B) doubleExplanation: 1. In C, a floating-point literal such as 3.14 has type double by default.
2. Adding suffix f (e.g., 3.14f) makes it a float.
3. Adding suffix L (e.g., 3.14L) makes it a long double.
4. So without a suffix, the default type is double.
Q395.Easy
Which of the following is NOT a user-defined data type?
1 : struct student { char name[ 10 ]; float marks; int roll; };
2 : long int m = 2.35 ;
3 : enum weekday {Sun, Mon, Tue, Wed};- 1
- 2
- 3
- Both 1 and 2
Show answer & explanation
Answer: (B) 2Explanation: 1) struct student is a structure type created by the programmer — user-defined.
2) enum weekday is an enumeration type created by the programmer — user-defined.
3) long int is a built-in (primitive) type supplied by C; the line just declares a variable m.
4) So statement 2 is not a user-defined data type.
Q396.Easy
State whether the following statement is True or False: The range of the float data type in C is -2.25e+308 to 2.25e+308.
- True
- False
Show answer & explanation
Answer: (B) FalseExplanation: 1) The float type is normally 4 bytes (32 bits) with about 7 significant digits.
2) Its typical range is roughly -3.4e+38 to 3.4e+38.
3) The range -2.25e+308 to 2.25e+308 belongs to double (8 bytes), not float.
4) Hence the statement is False.
Q397.Easy
What will be the output of the program?
#include<stdio.h>
int main()
{
int a = 150, b = 250, c;
c = (a == 150 || b > 250);
printf("c=%d\n", c);
return 0;
}- c=150
- c=250
- c=1
- c=400
Show answer & explanation
Answer: (C) c=1Explanation: Step 1: a = 150, b = 250.
Step 2: a == 150 is TRUE; b > 250 is FALSE.
Step 3: TRUE || FALSE = TRUE, which is stored in c as 1.
Step 4: printf prints c=1.
Q398.Easy
In the expression (a || b), the right-hand operand b is not evaluated if the left-hand operand a already determines the result.
- True
- False
Show answer & explanation
Answer: (A) TrueExplanation: Step 1: The || operator short-circuits.
Step 2: If a is non-zero (true), the whole expression is true regardless of b.
Step 3: So b is skipped and not evaluated. Hence the statement is True.
Q399.Easy
What will be the output of the program?
#include<stdio.h>
int main()
{
int k, num = 45;
k = (num > 5 ? (num <= 10 ? 100 : 200) : 500);
printf("%d\n", num);
return 0;
}- 200
- 45
- 100
- 500
Show answer & explanation
Answer: (B) 45Explanation: Step 1: num is initialized to 45.
Step 2: The line assigning k is a nested ternary; it only changes k, not num.
Step 3: printf prints the value of num, which is still 45.
Step 4: Output is 45.
Q400.Easy
What will be the output of the program?
#include <stdio.h>
int main() {
int a = 15, b = 9, r;
r = a != 6 || b == 3;
printf("r=%d\n", r);
return 0;
}- r=0
- r=1
- r=6
- r=3
Show answer & explanation
Answer: (B) r=1Explanation: Step 1: a=15, b=9, r declared.
Step 2: Evaluate a!=6 → 15!=6 is true (1).
Step 3: Evaluate b==3 → 9==3 is false (0).
Step 4: true || false = 1, so r=1.
Step 5: printf prints r=1.