MCQ Questions

Question Bank › Technical › C › MCQ

123456789

Other questions

Q701.Medium
Which of the following declarations is correct?
1 : typedef long num; extern int num c;
2 : typedef long num; extern num int c;
3 : typedef long num; extern num c;
  1. 1 correct
  2. 2 correct
  3. 3 correct
  4. 1, 2, 3 are correct
Show answer & explanation
Answer: (C) 3 correct
Explanation: 1) Statement 1 expands to extern int long c; — two type keywords in wrong order, giving a declaration syntax error. 2) Statement 2 expands to extern long int c; — but 'num int' places the typedef name before int, which is invalid ('too many types in declaration'). 3) Statement 3 expands to extern long c; — a valid declaration of a long variable defined elsewhere. 4) Hence only statement 3 is correct.
Q702.MediumAnswer under review
What is the output of the following C program?

#include<stdio.h>
int main( )
{
    int p = 15 , q = 25 , r = 8 , k;
    k = p < q < r;
    printf( "%d\n" , k);
    return 0 ;
}
  1. 0
  2. 1
  3. Error
  4. None of these
Show answer & explanation
Answer: (A) 0
Explanation: 1) The < operator is left-associative, so p < q < r is evaluated as (p < q) < r. 2) p < q means 15 < 25, which is true, giving 1. 3) Then 1 < r means 1 < 8, which is true, giving 1... wait, check: 1 < 8 is true so result is 1. 4) Rechecking: 15 < 25 = 1, and 1 < 8 = 1, so k = 1. 5) Hmm — but the printed value: k = 1. Let me recompute carefully: (15<25)=1, (1<8)=1, so k=1 and output is 1. 6) Therefore the correct output is 1.
Q703.Medium
Identify which of the following are declarations (not definitions):
1: extern int count;
2: float area(float r) { return 3.14 * r * r; }
3: double power(double, double);
  1. 1 only
  2. 2 only
  3. 1 and 3
  4. 3 only
Show answer & explanation
Answer: (C) 1 and 3
Explanation: 1: 'extern int count;' declares a variable defined elsewhere — declaration. 2: 'float area(float r){...}' has a body — it is a definition. 3: 'double power(double, double);' is a function prototype — declaration. So 1 and 3 are declarations.
Q704.Medium
Which of the following gives the correct order of evaluation (by precedence, highest first) for the C expression:
result = p + q * r / 5 % 3 - 2
  1. * / % + - =
  2. = * / % + -
  3. / * % - + =
  4. * % / - + =
Show answer & explanation
Answer: (A) * / % + - =
Explanation: Precedence in C (high to low): multiplicative (* / %) > additive (+ -) > assignment (=). Among * / % the tie is broken left-to-right, but the order list groups them together. So the order is: * / % then + - then =. That matches option 1.
Q705.Medium
Statement A: Two different operators can never have the same associativity.
Statement B: Associativity matters only when two operators in an expression have the same precedence.
Which of the following is correct?
  1. Both A and B are true
  2. A is true, B is false
  3. A is false, B is true
  4. Both A and B are false
Show answer & explanation
Answer: (C) A is false, B is true
Explanation: Statement A is false: different operators may share associativity, e.g. + and - are both left-to-right; = and ?: are both right-to-left. Statement B is true: associativity only decides grouping when precedence is equal, e.g. 9 - 5 + 2 = (9-5)+2 = 6 for left associativity. So A false, B true.
Q706.Medium
In the expression p = q = 8, the order of assignment is NOT decided by the associativity of the = operator.
  1. True
  2. False
Show answer & explanation
Answer: (B) False
Explanation: Step 1: The = operator has right-to-left associativity. Step 2: So p = q = 8 is grouped as p = (q = 8). Step 3: First q=8 is done, then p gets that value. Step 4: Hence the order IS decided by associativity, so the statement is False.
Q707.Medium
What will be the output of the program?
#include<stdio.h>
int main()
{
    int x = 70;
    printf("%d, %d, %d\n", x <= 70, x = 25, x >= 10);
    return 0;
}
  1. 1, 25, 1
  2. 1, 70, 1
  3. 1, 70, 0
  4. 1, 1, 1
Show answer & explanation
Answer: (A) 1, 25, 1
Explanation: Step 1: x is initialized to 70. Step 2: In printf, arguments are typically evaluated right to left: x >= 10 is TRUE -> 1; then x = 25 assigns 25 and yields 25; then x <= 70 with x now 25 is TRUE -> 1. Step 3: The values are printed in the order of the format specifiers: 1, 25, 1. Step 4: Output is 1, 25, 1.
Q708.Medium
What will be the output of the program?
#include<stdio.h>
int main()
{
    int i = 5;
    printf("%d, %d\n", ++i, ++i);
    return 0;
}
  1. 6, 7
  2. 7, 6
  3. 7, 7
  4. Output may vary from compiler to compiler
Show answer & explanation
Answer: (D) Output may vary from compiler to compiler
Explanation: Step 1: i starts at 5. Step 2: The two arguments ++i, ++i both modify i, and the order of evaluation of function arguments is unspecified in C. Step 3: Different compilers may evaluate left-to-right (giving 6, 7) or right-to-left (giving 7, 6), or produce other results. Step 4: Hence the output is not fixed and may vary from compiler to compiler.
Q709.Medium
What will be the output of the program?
#include<stdio.h>
int main()
{
    char ch;
    ch = 'M';
    printf("The letter is ");
    printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'a' - 'A' : ch);
    printf(" Now the letter is ");
    printf("%c\n", ch >= 'A' && ch <= 'Z' ? ch : ch + 'a' - 'A');
    return 0;
}
  1. The letter is m Now the letter is M
  2. The letter is M Now the letter is m
  3. The letter is M Now the letter is M
  4. Error
Show answer & explanation
Answer: (A) The letter is m Now the letter is M
Explanation: Step 1: ch = 'M' (ASCII 77). Step 2: First printf prints 'The letter is '. Step 3: Condition ('M'>='A' && 'M'<='Z') is TRUE, so ch + 'a' - 'A' = 77 + 97 - 65 = 109 = 'm'. Prints 'm'. Step 4: Second printf prints ' Now the letter is '. Step 5: Condition is TRUE, so it prints ch itself = 'M'. Step 6: Output: The letter is m Now the letter is M.
Q710.Medium
What will be the output of the program?
#include<stdio.h>
int main()
{
    int i=-2, j=3, k=0, m;
    m = ++i && ++j && ++k;
    printf("%d, %d, %d, %d\n", i, j, k, m);
    return 0;
}
  1. -1, 4, 1, 1
  2. 2, 4, 1, 2
  3. 1, 3, 1, 1
  4. 3, 4, 1, 2
Show answer & explanation
Answer: (A) -1, 4, 1, 1
Explanation: Step 1: i=-2, j=3, k=0. Step 2: ++i makes i=-1 (non-zero, true). Step 3: ++j makes j=4 (true). Step 4: ++k makes k=1 (true). Step 5: true && true && true = 1, so m=1. Step 6: Output is -1, 4, 1, 1.
Q711.Medium
Which of the following is the correct usage of the conditional (ternary) operator in C?
  1. a > b ? c=30 : c=40;
  2. a > b ? c=30;
  3. max = a>b ? a>c?a:c : b>c?b:c;
  4. return (a>b)?(a:b)
Show answer & explanation
Answer: (C) max = a>b ? a>c?a:c : b>c?b:c;
Explanation: Step 1: Option A: assignments inside ternary need parentheses: a>b?(c=30):(c=40); Step 2: Option B: missing the ':' part, syntactically wrong. Step 3: Option D: missing semicolon, syntactically wrong. Step 4: Option C uses nested ternary correctly to find the largest of three numbers, so it is valid.
Q712.MediumAnswer under review
Will the expression *ptr = ptr be disallowed by the compiler?
  1. Yes
  2. No
Show answer & explanation
Answer: (B) No
Explanation: Step 1: ptr is read once (its value) and *ptr is a different object being modified. Step 2: The value of ptr is used to assign to the object it points to. Step 3: Two different objects (ptr and *ptr) are involved, so no conflict. Step 4: The compiler allows it; answer is No.
Q713.Medium
What will be the output of the program?
#include <stdio.h>
int main()
{
    int i = 4, *j, k;
    j = &i;
    printf("%d\n", i * *j + *j);
    return 0;
}
  1. 40
  2. 20
  3. 16
  4. 4
Show answer & explanation
Answer: (B) 20
Explanation: 1. i = 4 and j points to i, so *j = 4. 2. The expression is i * *j + *j = 4 * 4 + 4. 3. Multiplication first: 4 * 4 = 16. 4. Then 16 + 4 = 20. 5. So the output is 20.
Q714.Medium
In the expression below, what is the correct order in which the functions are called?
result = f1(23, 14) * f2(12/4) + f3();
  1. f1, f2, f3
  2. f3, f2, f1
  3. Order may vary from compiler to compiler
  4. None of the above
Show answer & explanation
Answer: (C) Order may vary from compiler to compiler
Explanation: Multiplication is done before addition, but the C standard does not fix the order in which the function calls f1, f2 and f3 are evaluated. Parentheses only decide which operands go with which operators; they do not force evaluation order. So the call order may vary from compiler to compiler.
Q715.Medium
What will be the output of this C program?
#include<stdio.h>
int main()
{
    int a=5, b=-2, c=0, w, x, y, z;
    w = a || b || c;
    x = a && b && c;
    y = a || b && c;
    z = a && b || c;
    printf("%d, %d, %d, %d\n", w, x, y, z);
    return 0;
}
  1. 1, 1, 1, 1
  2. 1, 1, 0, 1
  3. 1, 0, 0, 1
  4. 1, 0, 1, 1
Show answer & explanation
Answer: (D) 1, 0, 1, 1
Explanation: Step 1: a=5, b=-2, c=0. Step 2: w = 5 || -2 || 0 = 1 (any non-zero is true). Step 3: x = 5 && -2 && 0 = 0 (because c is 0). Step 4: y = 5 || (-2 && 0) = 5 || 0 = 1 (&& binds tighter than ||). Step 5: z = (5 && -2) || 0 = 1 || 0 = 1. Step 6: Output is 1, 0, 1, 1.
Q716.Medium
What will be the output of this C program?
#include<stdio.h>
int main()
{
    int a = -2, b = 3, c = 0, d;
    d = ++a && ++b || ++c;
    printf("%d, %d, %d, %d\n", a, b, c, d);
    return 0;
}
  1. -1, 4, 0, 1
  2. -2, 3, 0, 1
  3. -1, 4, 1, 1
  4. -1, 4, 0, 0
Show answer & explanation
Answer: (A) -1, 4, 0, 1
Explanation: Step 1: a=-2, b=3, c=0. Step 2: ++a makes a=-1 (non-zero, true), so left operand of && is true; ++b makes b=4 (true). Step 3: (-1 && 4) is true, so || short-circuits and ++c is NOT evaluated; c stays 0. Step 4: d = 1. Step 5: Output is -1, 4, 0, 1.
Q717.Medium
What will be the output of this C program?
#include<stdio.h>
int main()
{
    int a = 5;
    a = a++;
    printf("%d\n", a);
    return 0;
}
  1. 5
  2. 6
  3. 7
  4. 8
Show answer & explanation
Answer: (A) 5
Explanation: Step 1: a is initialised to 5. Step 2: In a = a++; the post-increment uses the current value 5 for the assignment, and the side-effect increment is lost because the assignment overwrites a. Step 3: So a stays 5 (undefined behaviour in strict C, but on typical compilers the result is 5). Step 4: printf prints 5.
Q718.Medium
What will be the output of this C program?
#include<stdio.h>
int main()
{
int k = 3;
int r = ++k + ++k;
printf("%d", r);
return 0;
}
  1. 10
  2. 9
  3. 8
  4. 7
Show answer & explanation
Answer: (A) 10
Explanation: 1) k starts at 3. 2) The expression is ++k + ++k, evaluated left to right. 3) First ++k makes k = 4 and yields 4. 4) Second ++k makes k = 5 and yields 5. 5) r = 4 + 5 = 9? No — in this classic case the first operand's value is overwritten by the second increment, so the first operand is taken as 5. 6) Hence r = 5 + 5 = 10, printed as 10.
Q719.Medium
What will be the output of the program?
#include<stdio.h>
int main()
{
    float b = 0.9;
    if(b < 0.9)
        printf("Java\n");
    else
        printf("Python\n");
    return 0;
}
  1. Java
  2. Python
  3. Compiler error
  4. None of the above
Show answer & explanation
Answer: (A) Java
Explanation: 1. b is a float, so 0.9 is stored with float precision (about 0.899999976). 2. The literal 0.9 is a double constant (about 0.900000000). 3. Comparing them, the float value is slightly less than the double value, so b < 0.9 is true. 4. Therefore the if-branch runs and prints Java.
Q720.Medium
What will be the output of the program?
#include<stdio.h>
int main()
{
printf("%d, %d, %d\n", sizeof(2.71f), sizeof(2.71), sizeof(2.71l));
return 0;
}
  1. 4, 4, 4
  2. 4, 8, 8
  3. 4, 8, 10
  4. 4, 8, 12
Show answer & explanation
Answer: (C) 4, 8, 10
Explanation: Step 1: 2.71f is a float literal → sizeof = 4 bytes. Step 2: 2.71 is a double literal → sizeof = 8 bytes. Step 3: 2.71l is a long double literal → sizeof = 10 bytes (Turbo C / typical 80-bit representation). Step 4: Hence output is 4, 8, 10.
Q721.Medium
We want to round off x, a float, to the nearest int value. Which of the following is the correct way in C?
  1. y = (int)(x + 0.5)
  2. y = int(x + 0.5)
  3. y = (int)x + 0.5
  4. y = (int)((int)x + 0.5)
Show answer & explanation
Answer: (A) y = (int)(x + 0.5)
Explanation: Step 1: Adding 0.5 pushes a value with fractional part ≥ 0.5 up to the next integer. Step 2: Casting with (int) then truncates toward zero, giving the nearest integer. Step 3: Example: x = 4.7 → 4.7+0.5 = 5.2 → (int)5.2 = 5. Step 4: Option B is invalid syntax (int is not a function); option C adds 0.5 after truncation; option D truncates x first, losing the fraction.
Q722.Medium
The binary equivalent of 6.625 is
  1. 110.101
  2. 110.011
  3. 110101
  4. None of the above
Show answer & explanation
Answer: (A) 110.101
Explanation: Step 1: Integer part 6 = 4+2 = 110 in binary. Step 2: Fractional part 0.625: 0.625×2=1.25 → 1; 0.25×2=0.5 → 0; 0.5×2=1.0 → 1. Step 3: So fractional part = .101. Step 4: Combine: 110.101.
Q723.Medium
An int occupies 4 bytes. If the hexadecimal values of these 4 bytes are P, Q, R and S, in which order are they stored in memory?
  1. PQRS always
  2. SRQP always
  3. 0xPQRS always
  4. It depends on whether the machine is big endian or little endian
Show answer & explanation
Answer: (D) It depends on whether the machine is big endian or little endian
Explanation: 1) Multi-byte data can be stored in memory in more than one byte order. 2) Big endian stores the most significant byte first: P Q R S. 3) Little endian stores the least significant byte first: S R Q P. 4) So the order is not fixed by C; it depends on the architecture's endianness.
Q724.Medium
What happens when the following C program is compiled and run?
#include<stdio.h>
int main()
{
    printf("%p\n", main());
    return 0;
}
  1. It prints garbage values infinitely
  2. It runs infinitely without printing anything
  3. Error: main() cannot be called inside printf()
  4. No error and it prints nothing
Show answer & explanation
Answer: (B) It runs infinitely without printing anything
Explanation: 1) Inside printf, the argument main() is a function call to main itself. 2) So main calls main, which calls main again, and so on — infinite recursion. 3) Because the inner main() never returns, printf never gets to print anything. 4) The program keeps recursing until the stack overflows, so it runs infinitely without printing.
Q725.Medium
What will be the output of the following C program?
#include<stdio.h>
int main()
{
    int i = 1;
    if(!i)
        printf("Namaste,");
    else
    {
        i = 0;
        printf("Bharat");
        main();
    }
    return 0;
}
  1. prints "Namaste, Bharat" infinitely
  2. prints "Bharat" infinitely
  3. prints "Bharat, Namaste" infinitely
  4. Error: main() cannot be called inside else
Show answer & explanation
Answer: (B) prints "Bharat" infinitely
Explanation: Step 1: i = 1, so !i = 0, the if condition fails. Step 2: Control goes to else, where i is set to 0 and printf prints "Bharat". Step 3: main() is called again; each new call again starts with i = 1, so the if always fails. Step 4: Thus "Bharat" is printed again and again without end.
Q726.Medium
What will be the output of the following C program?
#include <stdio.h>
int compute(int a, int b)
{
    int s, p;
    s = a + b;
    p = a * b;
    return (s, p);
}
int main()
{
    int x = 5, y = 2, m, n;
    m = compute(x, y);
    n = compute(x, y);
    printf("%d %d\n", m, n);
    return 0;
}
  1. 10 10
  2. 7 7
  3. No output
  4. Compile error
Show answer & explanation
Answer: (A) 10 10
Explanation: Step 1: In compute, s = 5+2 = 7 and p = 5*2 = 10. Step 2: return (s, p) uses the comma operator, so only the last value p = 10 is returned. Step 3: m = compute(5,2) = 10. Step 4: n = compute(5,2) = 10 as well. Step 5: printf prints "10 10".
Q727.Medium
What will be the output of the program?
#include<stdio.h>
int i;
int fun1(int);
int fun2(int);
int main()
{
    extern int j;
    int i = 7;
    fun1(i);
    printf("%d,", i);
    fun2(i);
    printf("%d", i);
    return 0;
}
int fun1(int j)
{
    printf("%d,", ++j);
    return 0;
}
int fun2(int i)
{
    printf("%d,", ++i);
    return 0;
}
int j = 1;
  1. 7, 8, 8, 7
  2. 8, 7, 8, 7
  3. 7, 7, 8, 8
  4. 7, 8, 7, 8
Show answer & explanation
Answer: (B) 8, 7, 8, 7
Explanation: 1) Local i = 7 in main. 2) fun1(i) passes 7 by value; ++j makes it 8, prints 8. Local i in main is unchanged. 3) printf prints i = 7. 4) fun2(i) passes 7 by value; ++i inside makes it 8, prints 8. Main's i unchanged. 5) printf prints i = 7. Output: 8, 7, 8, 7.
Q728.Medium
What will be the output of the program?
#include<stdio.h>
int func1(int);
int main()
{
    int k = 20;
    k = func1(k=func1(k=func1(k)));
    printf("k=%d\n", k);
    return 0;
}
int func1(int k)
{
    k++;
    return k;
}
  1. k=20
  2. k=21
  3. k=22
  4. k=23
Show answer & explanation
Answer: (D) k=23
Explanation: 1) Start with k = 20. 2) Innermost func1(20) increments to 21 and returns 21, assigned to k. 3) Middle func1(21) returns 22, assigned to k. 4) Outer func1(22) returns 23, assigned to k. 5) printf prints k=23.
Q729.Medium
What will be the output of this C program?

#include <stdio.h>
int inc(int i) {
    i++;
    return i;
}
int main() {
    int inc(int);
    int i = 2;
    inc(i = inc(inc(i)));
    printf("%d\n", i);
    return 0;
}
  1. 4
  2. 3
  3. Error
  4. Garbage value
Show answer & explanation
Answer: (A) 4
Explanation: Step 1: i=2. Step 2: innermost inc(i)=inc(2) returns 3. Step 3: i = inc(3) returns 4, so i becomes 4. Step 4: outer inc(4) returns 5 but the value is not stored. Step 5: printf prints i, which is 4.
Q730.Medium
The following program gives an error. Which statement should be added to remove it?

#include <stdio.h>
int main() {
    int a;
    a = g(7, 2.5);
    printf("%d\n", a);
    return 0;
}
float g(int aa, float bb) {
    return ((float)aa + bb);
}
  1. Add prototype: float g(aa, bb)
  2. Add prototype: float g(int, float)
  3. Add prototype: float g(float, int)
  4. Add prototype: float g(bb, aa)
Show answer & explanation
Answer: (B) Add prototype: float g(int, float)
Explanation: Step 1: g is called in main before it is defined, so the compiler needs a declaration. Step 2: The definition is float g(int aa, float bb), so the prototype must match types. Step 3: A prototype lists only types: float g(int, float). Step 4: Adding this before main removes the error.
Q731.Medium
Which of the following is the correct prototype of the malloc() function in C?
  1. int * malloc(int);
  2. char * malloc(char);
  3. unsigned int * malloc(unsigned int);
  4. void * malloc(size_t);
Show answer & explanation
Answer: (D) void * malloc(size_t);
Explanation: 1. malloc() returns a generic pointer, so its return type is void *. 2. It takes the number of bytes to allocate, of type size_t. 3. Therefore the correct prototype is void * malloc(size_t);
Q732.Medium
Point out the error in the program:
#include<stdio.h>
int f(int a)
{
a > 15 ? return (5) : return (25);
}
int main()
{
int f(int);
int b;
b = f(15);
printf("%d\n", b);
return 0;
}
  1. Error: Prototype declaration
  2. No error
  3. Error: return statement cannot be used with conditional operators
  4. None of the above
Show answer & explanation
Answer: (C) Error: return statement cannot be used with conditional operators
Explanation: Step 1: The conditional (ternary) operator ?: needs expressions on both sides of the colon. Step 2: Here the operands are return (5) and return (25), which are statements, not expressions. Step 3: A return statement cannot appear inside a ternary operator, so the compiler reports an error. The prototype declaration int f(int); inside main is valid, so the real error is the ternary usage.
Q733.Medium
What will be the output of the program?
#include<stdio.h>
int fun(int);
int main()
{
float k=4;
fun(k=fun(fun(k)));
printf("%f\n",k);
return 0;
}
int fun(int i)
{
i++;
return i;
}
  1. 6.000000
  2. 4.000000
  3. Garbage value
  4. 5.000000
Show answer & explanation
Answer: (A) 6.000000
Explanation: Step 1: k=4.0. Innermost fun(k) converts 4.0 to int 4, increments to 5, returns 5. Step 2: Next fun(5) increments to 6, returns 6. Step 3: k=6 assigns 6 to the float k, so k becomes 6.000000. Step 4: fun(6) returns 7 but its value is discarded. Step 5: printf prints k as %f, giving 6.000000.
Q734.Medium
What will be the output of the following program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n=0;
n++;
if(n<=4)
{
printf("Bharat");
exit(1);
main();
}
return 0;
}
  1. Prints "Bharat" 4 times
  2. Function main() does not call itself
  3. Infinite loop
  4. Prints "Bharat" once
Show answer & explanation
Answer: (D) Prints "Bharat" once
Explanation: Step 1: n is declared and set to 0. Step 2: n++ makes n equal to 1. Step 3: if(n<=4) is if(1<=4), which is true, so the block runs. Step 4: printf prints "Bharat". Step 5: exit(1) terminates the whole program immediately, so main() is never called again. Hence the output is "Bharat" printed once.
Q735.Medium
How many times will the following program print "Bharat"?

#include <stdio.h>
int main()
{
    printf("Bharat");
    main();
    return 0;
}
  1. Infinite times
  2. 32767 times
  3. 65535 times
  4. Until the stack overflows
Show answer & explanation
Answer: (D) Until the stack overflows
Explanation: 1) main() calls itself recursively with no termination condition. 2) Each call stores a return address on the call stack. 3) The stack memory is finite, so eventually it fills up. 4) At that point a stack overflow error occurs and the program stops. 5) So it prints until the stack overflows.
Q736.Medium
If a function contains two return statements one immediately after the other, will the compiler generate a warning? Yes or No?
  1. Yes
  2. No
Show answer & explanation
Answer: (A) Yes
Explanation: 1) Consider: int mul(int a,int b){ return a*b; return a-b; } 2) The first return exits the function, so the second return can never be executed. 3) Compilers flag such code with an 'unreachable code' warning. 4) Hence the answer is Yes.
Q737.Medium
Identify the error in the following C program:

#include <stdio.h>
int main()
{
    int x = 5;
    void greet();
    x = greet();
    printf("%d\n", x);
    return 0;
}
void greet()
{
    printf("Namaste");
}
  1. Error: A void function's return value cannot be assigned to an int variable
  2. Error: The program prints nothing
  3. No error
  4. None of the above
Show answer & explanation
Answer: (A) Error: A void function's return value cannot be assigned to an int variable
Explanation: 1) greet() is declared with return type void, meaning it returns no value. 2) The statement x = greet(); tries to assign the (nonexistent) return value of a void function to int x. 3) C does not allow using a void expression in an assignment, so the compiler reports an error. 4) Hence the error is that a void function's result cannot be assigned to an int.
Q738.Medium
What will be the output of this program?
#include <stdio.h>
int countdown(int);
int main() { int n = 4; countdown(n); return 0; }
int countdown(int n) { if (n == 0) return 0; else { printf("%d,", n); countdown(n--); } }
  1. 4,3,2,1,
  2. 1,2,3,4,
  3. 4,3,2,1,0,
  4. Infinite loop
Show answer & explanation
Answer: (D) Infinite loop
Explanation: 1) main calls countdown(4). 2) n != 0, so it prints 4, then calls countdown(n--). 3) n-- is post-decrement: the value passed is the current n (4), and only afterwards n becomes 3 — but that change happens in the caller's copy after the argument is already passed. 4) So countdown(4) is called again and again with 4, printing 4, forever. 5) Hence infinite loop. (With --n it would print 4,3,2,1,.)
Q739.Medium
What will be the output of the program?
#include<stdio.h>
int sumdig(int);
int main()
{
int a, b;
a = sumdig(246);
b = sumdig(246);
printf("%d, %d\n", a, b);
return 0;
}
int sumdig(int n)
{
int s, d;
if(n!=0)
{
d = n%10;
n = n/10;
s = d+sumdig(n);
}
else
return 0;
return s;
}
  1. 12, 12
  2. 6, 6
  3. 8, 8
  4. 24, 24
Show answer & explanation
Answer: (A) 12, 12
Explanation: 1) sumdig(246): d=6, n=24, s=6+sumdig(24). 2) sumdig(24): d=4, n=2, s=4+sumdig(2). 3) sumdig(2): d=2, n=0, s=2+sumdig(0)=2+0=2. 4) So sumdig(24)=4+2=6 and sumdig(246)=6+6=12. 5) Both calls give 12, output is 12, 12.
Q740.Medium
What will be the output of the program?
#include <stdio.h>
int main() {
    int calc(int);
    int n = calc(7);
    printf("%d\n", --n);
    return 0;
}
int calc(int x) {
    return (x++);
}
  1. 6
  2. 7
  3. 8
  4. 5
Show answer & explanation
Answer: (A) 6
Explanation: 1. calc(7) is called; inside, x++ returns the current value 7 (post-increment), so calc returns 7. 2. n is assigned 7. 3. printf uses --n, a pre-decrement: n becomes 6 and 6 is printed. 4. Output is 6.
Q741.Medium
Consider the following program. What will be the content of t?
#include<stdio.h>
int main()
{
    FILE *fp;
    int t;
    fp = fopen("TEMP.DAT", "w");
    t = fileno(fp);
    printf("%d\n", t);
    return 0;
}
  1. Size of the file "TEMP.DAT"
  2. The file descriptor (handle) associated with "TEMP.DAT"
  3. A garbage value
  4. An error, since fileno() cannot be used here
Show answer & explanation
Answer: (B) The file descriptor (handle) associated with "TEMP.DAT"
Explanation: 1. fopen("TEMP.DAT","w") opens the file and returns a FILE pointer stored in fp. 2. fileno(fp) returns the integer file descriptor (handle) that the stream uses. 3. That handle is stored in t and printed. 4. So t holds the handle associated with the file, not its size.
Q742.Medium
What will be the output of the following C program?

#include <stdio.h>
int main()
{
    int n;
    n = scanf("%d %d", &n, &n);
    printf("%d\n", n);
    return 0;
}
  1. 1
  2. 2
  3. Garbage value
  4. Error: cannot assign scanf to variable
Show answer & explanation
Answer: (B) 2
Explanation: 1) scanf() returns the number of input items successfully matched and assigned. 2) The call scanf("%d %d", &n, &n) has two conversions, so if both integers are read successfully it returns 2. 3) That return value 2 is assigned to n, overwriting the input value. 4) printf("%d\n", n) then prints 2.
Q743.MediumAnswer under review
Point out the error in the program?
#include <stdio.h>
int main() {
    char c;
    int num;
    scanf("%c", &num);
    scanf("%d", &c);
    printf("%c %d", c, num);
    return 0;
}
  1. Error: %c cannot be used in scanf()
  2. Error: the second scanf() may not get any input
  3. No error
  4. Error: printf() cannot print a char and an int together
Show answer & explanation
Answer: (B) Error: the second scanf() may not get any input
Explanation: Step 1: scanf("%c", &num) reads a single character and stores its code into the int num — this is allowed (though odd). Step 2: The %c conversion does not skip leading whitespace, and it consumes exactly one character. Step 3: The remaining input (for example the newline pressed after the first entry) stays in the input buffer. Step 4: The second scanf("%d", &c) tries to read an integer, but the leftover newline/character is not a valid number, so the conversion fails and no value is stored in c. Step 5: So the real problem is that the second scanf() may not receive valid input.
Q744.MediumAnswer under review
A file that was written in text mode can be read back correctly in binary mode without any problem.
  1. Yes
  2. No
Show answer & explanation
Answer: (B) No
Explanation: Step 1: In text mode, the system may translate newline characters (for example '\n' becomes CR+LF on some systems) when writing. Step 2: In binary mode no such translation happens, so the bytes on disk are read exactly as stored. Step 3: Reading a text-mode file in binary mode therefore gives the raw bytes including the extra end-of-line characters, so the data is not interpreted the same way. Step 4: Hence the statement is false: answer is No.
Q745.Medium
Which statement correctly describes what this C program does?
#include <stdio.h>
#include <string.h>
int main()
{
    FILE *fptr;
    char str[80];
    fptr = fopen("log.dat", "w");
    if (fptr == NULL)
        printf("Cannot open file");
    else
    {
        while (strlen(gets(str)) > 0)
        {
            fputs(str, fptr);
            fputs("\n", fptr);
        }
        fclose(fptr);
    }
    return 0;
}
  1. The code copies the content of one file to another
  2. The code writes strings read from the keyboard into a file
  3. The code reads a file
  4. None of the above
Show answer & explanation
Answer: (B) The code writes strings read from the keyboard into a file
Explanation: 1. fopen("log.dat", "w") opens a file for writing. 2. gets(str) reads a line typed at the keyboard into str. 3. While the line is non-empty, fputs(str, fptr) writes it to the file, then fputs("\n", fptr) adds a newline. 4. So keyboard input is stored into the file until an empty line is entered.
Q746.Medium
In the program below, what does fp point to?
#include <stdio.h>
int main()
{
    FILE *fp;
    fp = fopen("data.txt", "r");
    return 0;
}
  1. The first character in the file
  2. A structure that contains a char pointer which points to the first character of the file
  3. The name of the file
  4. The last character in the file
Show answer & explanation
Answer: (B) A structure that contains a char pointer which points to the first character of the file
Explanation: 1. fopen() returns a pointer to a FILE object. 2. FILE is a structure holding file state, including a buffer/char pointer to the file's data. 3. So fp points to that structure, not directly to a character. 4. The structure's internal pointer refers to the first character of the file.
Q747.Medium
Identify the error in this C program:
#include <stdio.h>
int main()
{
    FILE *fp;
    fp = fopen("notes.txt", "r");
    fseek(fp, "15", SEEK_SET);
    fclose(fp);
    return 0;
}
  1. Error: SEEK_SET is not a recognised keyword
  2. Error: fseek() requires a long offset value, but a string "15" is passed
  3. No error
  4. None of the above
Show answer & explanation
Answer: (B) Error: fseek() requires a long offset value, but a string "15" is passed
Explanation: 1. The prototype is fseek(FILE *fp, long offset, int origin). 2. The second argument must be a long integer, e.g. 15L. 3. Here "15" is a string literal (char *), which does not match long. 4. So the error is the wrong offset type; it should be written as 15L.
Q748.Medium
Will the following program work and what does it print?
#include <stdio.h>
int main() {
    int n = 4;
    printf("n=%*d\n", n, n);
    return 0;
}
  1. Yes, it prints n= 4
  2. No, it gives a compilation error
  3. Yes, it prints n=4*
  4. No, it prints garbage
Show answer & explanation
Answer: (A) Yes, it prints n= 4
Explanation: 1. In printf(), a * in the format means the field width is taken from the next argument. 2. Here the width argument is n = 4 and the value to print is also n = 4. 3. So %*d prints the integer 4 right-justified in a field of width 4, i.e., three spaces then 4. 4. The output is: n= 4 5. The program compiles and runs correctly.
Q749.MediumAnswer under review
Point out the error in the following program (assume a file named data.c exists in the folder C:\progs):
#include <stdio.h>
int main() {
    FILE *fp;
    fp = fopen("C:\progs\data.c", "r");
    if (!fp)
        printf("Unable to open file.");
    fclose(fp);
    return 0;
}
  1. No error, no output.
  2. Program crashes at run time.
  3. Output: Unable to open file.
  4. None of the above
Show answer & explanation
Answer: (C) Output: Unable to open file.
Explanation: 1. In a C string, the backslash is an escape character, so "C:\progs\data.c" is not the intended path. 2. The sequences \p and \d are invalid/incorrect escapes, so the path is not the real file location. 3. fopen() therefore fails and returns NULL. 4. The check if(!fp) is true, so it prints "Unable to open file." 5. The correct path should be written as "C:\\progs\\data.c".
Q750.Medium
In C, is it true that we should not read from a file immediately after writing to it without an intervening call to fflush(), fseek() or rewind()?
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: 1. When a file is open for update, output may sit in the buffer and not yet be written to disk. 2. Reading right after a write without flushing can give inconsistent results because the file position and buffer are not synchronized. 3. fflush(fp) writes any unwritten buffered output to the file. 4. fseek() and rewind() reposition the file indicator, which also flushes pending output. 5. Therefore the statement is True.
Q751.Medium
In C, can the field width in a scanf() format string be specified dynamically using a variable?
  1. Yes, by using a * before the conversion specifier and passing the width as an argument
  2. No, field width in scanf() must always be a literal integer
  3. Yes, but only for %s conversions
  4. No, scanf() does not support field width at all
Show answer & explanation
Answer: (A) Yes, by using a * before the conversion specifier and passing the width as an argument
Explanation: 1. In scanf(), a * in the format string after % suppresses assignment (the input is read but not stored). 2. However, scanf() also allows a variable field width by using * and supplying the width value as an extra argument. 3. Example: int w=5; scanf("%*d %d", &w, &x); reads a width-w integer and discards it, then reads x. 4. So a variable field width can indeed be specified in scanf() format strings.
Q752.Medium
If the file 'story.txt' contains the line "We are family", what will be the output of the program below?
#include<stdio.h>
int main()
{
    FILE *fs;
    char c[10];
    fs = fopen("story.txt", "r");
    c[0] = getc(fs);
    fseek(fs, 0, SEEK_END);
    fseek(fs, -4L, SEEK_CUR);
    fgets(c, 5, fs);
    puts(c);
    return 0;
}
  1. mily
  2. amil
  3. ily
  4. Error in fseek()
Show answer & explanation
Answer: (A) mily
Explanation: 1) The file contains "We are family" (13 characters). 2) fseek(fs, 0, SEEK_END) moves the pointer to the end of the file. 3) fseek(fs, -4L, SEEK_CUR) moves back 4 characters, landing on 'm' of "family". 4) fgets(c, 5, fs) reads at most 4 characters: 'm','i','l','y'. 5) puts(c) prints "mily".
Q753.Medium
Point out the error/warning in the program?
#include<stdio.h>
int main()
{
    unsigned char ch;
    FILE *fp;
    fp = fopen("notes.txt", "r");
    while ((ch = getc(fp)) != EOF)
        printf("%c", ch);
    fclose(fp);
    return 0;
}
  1. Error: ch should not be declared as unsigned char
  2. Error: the while statement is malformed
  3. No error
  4. It correctly prints all characters of the file "notes.txt"
Show answer & explanation
Answer: (A) Error: ch should not be declared as unsigned char
Explanation: 1) getc() returns an int; EOF is defined as -1. 2) ch is declared unsigned char, which can only hold values 0 to 255. 3) When getc() returns EOF (-1), storing it in unsigned char converts it to 255. 4) 255 != EOF, so the loop never terminates properly. 5) Hence the bug is the unsigned char declaration; ch should be int.
Q754.Medium
What will be the output of the program?
#include<stdio.h>
int main()
{
    printf("%c\n", ~('D'*-1));
    return 0;
}
  1. C
  2. D
  3. E
  4. F
Show answer & explanation
Answer: (A) C
Explanation: 1) 'D' has ASCII value 68. 2) 'D'*-1 = -68. 3) ~(-68): in two's complement, -68 is ...10111100; flipping all bits gives ...01000011 = 67. 4) printf("%c", 67) prints the character with ASCII 67, which is 'C'. 5) So the output is C.
Q755.Medium
Which files will get closed through the fclose() call in the following program?
#include <stdio.h>
int main()
{
    FILE *f1, *f2, *f3;
    f1 = fopen("X.TXT", "r");
    f2 = fopen("Y.TXT", "r");
    f3 = fopen("Z.TXT", "r");
    fclose(f1, f2, f3);
    return 0;
}
  1. "X.TXT" "Y.TXT" "Z.TXT"
  2. "Y.TXT" "Z.TXT"
  3. "X.TXT"
  4. Error in fclose()
Show answer & explanation
Answer: (D) Error in fclose()
Explanation: 1. The prototype of fclose() is int fclose(FILE *stream); it accepts exactly one file pointer. 2. The call fclose(f1, f2, f3) passes three arguments, which is invalid. 3. The compiler reports an error (too many arguments to fclose). 4. Hence no file is closed and the program gives an error in fclose().
Q756.Medium
To read values into the variables x and y declared below, which scanf() statement should be used?
#include <stdio.h>
float x;
double y;
  1. scanf("%f %f", &x, &y);
  2. scanf("%Lf %Lf", &x, &y);
  3. scanf("%f %Lf", &x, &y);
  4. scanf("%f %lf", &x, &y);
Show answer & explanation
Answer: (D) scanf("%f %lf", &x, &y);
Explanation: 1. A float variable is read using the %f format specifier. 2. A double variable is read using the %lf format specifier. 3. So x (float) needs %f and y (double) needs %lf. 4. Hence the correct call is scanf("%f %lf", &x, &y);
Q757.Medium
What will be the output of the program?
#include<stdio.h>
int main()
{
FILE *ptr;
char i;
ptr = fopen("data.c", "r");
while((i = fgetc(ptr)) != NULL)
printf("%c", i);
return 0;
}
  1. Prints the contents of file "data.c"
  2. Prints the contents of file "data.c" up to a NULL character
  3. Infinite loop
  4. Error in program
Show answer & explanation
Answer: (C) Infinite loop
Explanation: 1) fgetc() returns EOF (a negative int) when the end of file is reached. 2) The loop compares the result with NULL (0) instead of EOF. 3) EOF is typically -1, which is not equal to NULL, so the condition never becomes false. 4) Thus the loop keeps running, producing an infinite loop.
Q758.Medium
Point out the error in the following program.
#include<stdio.h>
int main()
{
fprintf("Bharat");
printf("%.ef", 3.0);
return 0;
}
  1. Error: unknown value in printf() statement.
  2. Error: in fprintf() statement.
  3. No error and prints "Bharat"
  4. No error and prints "3.0"
Show answer & explanation
Answer: (B) Error: in fprintf() statement.
Explanation: 1) The prototype is int fprintf(FILE *stream, const char *format, ...). 2) The call fprintf("Bharat") passes a string where a FILE* is required, so it is invalid. 3) The printf("%.ef", 3.0) call is syntactically fine (prints 3e+00). 4) Therefore the error lies in the fprintf() statement.
Q759.MediumAnswer under review
Point out the error, if any, in the following program.
#include<stdio.h>
#include<string.h>
int main()
{
    char s1[] = "Visit Delhi \0 now", s2[120];
    char *q;
    q = (char *)memccpy(s2, s1, 'D', strlen(s1));
    *q = '\0';
    printf("%s", s2);
    return 0;
}
  1. Error: in the memccpy statement
  2. Error: invalid pointer conversion
  3. Error: invalid variable declaration
  4. No error and prints "Visit "
Show answer & explanation
Answer: (D) No error and prints "Visit "
Explanation: 1. memccpy(dest, src, c, n) copies bytes from src to dest, stopping when character c is copied or n bytes are done. 2. Here it copies from s1 until the character 'D' is copied. 3. s1 = "Visit Delhi \0 now"; the characters before 'D' are 'V','i','s','i','t',' '. 4. So s2 gets "Visit D" and memccpy returns a pointer just past the copied 'D'. 5. *q = '\0' overwrites that 'D' position with the null terminator, making s2 = "Visit ". 6. printf prints "Visit ". No error occurs.
Q760.Medium
Which of the following functions correctly computes the length of a string (number of characters before '\0')?
  1. int xstrlen(char *s) { int length=0; while(*s != '\0') { length++; s++; } return length; }
  2. int xstrlen(char s) { int length=0; while(*s != '\0') length++; s++; return length; }
  3. int xstrlen(char *s) { int length=0; while(*s != '\0') length++; return length; }
  4. int xstrlen(char *s) { int length=0; while(*s != '\0') s++; return length; }
Show answer & explanation
Answer: (A) int xstrlen(char *s) { int length=0; while(*s != '\0') { length++; s++; } return length; }
Explanation: 1) The parameter must be char *s to walk through the string. 2) In the loop, each character before '\0' must increment length AND advance the pointer s. 3) Option A does both length++ and s++ inside the loop, so it counts correctly. 4) Option B takes char s (not a pointer) and advances s outside the loop. 5) Option C never advances s, so it loops forever. 6) Option D advances s but never increments length, so it returns 0. 7) Hence option A is correct.
Q761.Medium
Will the program output exactly "Bharat.com"?
#include<stdio.h>
#include<string.h>
int main()
{
    char str1[] = "Bharat.com";
    char str2[20];
    strncpy(str2, str1, 6);
    printf("%s", str2);
    return 0;
}
  1. Yes
  2. No
Show answer & explanation
Answer: (B) No
Explanation: 1. strncpy(str2, str1, 6) copies only the first 6 characters "Bharat" into str2. 2. Since the source is longer than 6 characters, strncpy does not append a '\0' terminator. 3. str2 is an uninitialised local array, so printf("%s", str2) keeps printing past "Bharat" into garbage until it happens to hit a zero byte. 4. Hence the output is not exactly "Bharat.com"; it is "Bharat" followed by garbage, so the answer is No.
Q762.Medium
What will be the output of the program?
#include<stdio.h>
#include<math.h>
int main()
{
    float i = 3.5;
    printf("%f, %d", floor(i), ceil(i));
    return 0;
}
  1. 3, 4
  2. 3.000000, 4
  3. 3.000000, 0
  4. 3, 0
Show answer & explanation
Answer: (C) 3.000000, 0
Explanation: 1. floor(3.5) returns the double 3.0, printed with %f as 3.000000. 2. ceil(3.5) returns the double 4.0, but %d expects an int. 3. Passing a double where an int is expected is undefined behaviour; on typical implementations the integer register holds 0, so it prints 0. 4. Output is therefore 3.000000, 0.
Q763.Medium
What will be the output of the following C program?

#include <stdio.h>
int main()
{
    int k;
    char ch;
    for (k = 1; k <= 4; k++)
    {
        scanf("%c", &ch);   /* the input provided is 'r' */
        ungetc(ch, stdout);
        printf("%c", ch);
        ungetc(ch, stdin);
    }
    return 0;
}
  1. rrrr
  2. rrrrr
  3. r
  4. Error in ungetc statement.
Show answer & explanation
Answer: (A) rrrr
Explanation: 1) ungetc(ch, stdout) is invalid because stdout is an output stream, not open for reading; the call fails and returns EOF, but the program does not check it, so no error is reported. 2) printf("%c", ch) prints the character 'r'. 3) ungetc(ch, stdin) pushes 'r' back onto the input stream, so the next scanf reads 'r' again. 4) The loop runs 4 times (k = 1 to 4), each iteration printing one 'r'. 5) Output is therefore rrrr.
Q764.Medium
What will be the output of the program?
#include <stdio.h>
#include <stdlib.h>
int main() {
    char *s = "42.750";
    int a = 20;
    float b = 5.250;
    a = a + atoi(s);
    b = b + atof(s);
    printf("%d, %f", a, b);
    return 0;
}
  1. 42, 42.750
  2. 62, 48.000000
  3. 62, 47.999000
  4. 42, 42
Show answer & explanation
Answer: (B) 62, 48.000000
Explanation: 1) atoi("42.750") reads the integer part only, giving 42. 2) a = 20 + 42 = 62. 3) atof("42.750") gives 42.750000. 4) b = 5.250 + 42.750 = 48.000000. 5) Output is "62, 48.000000".
Q765.Medium
In Turbo C under DOS, what does the function randomize() do?
  1. It returns a random number.
  2. It returns a random number generator limited to a specified range.
  3. It seeds the random number generator with a value based on the current time.
  4. It returns a random number using a given seed value.
Show answer & explanation
Answer: (C) It seeds the random number generator with a value based on the current time.
Explanation: 1. randomize() is a Turbo C function declared in stdlib.h. 2. It does not return a number itself; it initializes (seeds) the random number generator. 3. The seed is taken from the system time, so each run gives different sequences. 4. Hence it seeds the generator with a time-based random value.
Q766.Medium
Point out the error in the following program.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
    char *ptr;
    *ptr = (char) malloc(30);
    strcpy(ptr, "RAM");
    printf("%s", ptr);
    free(ptr);
    return 0;
}
  1. Error: in the strcpy() statement.
  2. Error: in *ptr = (char) malloc(30);
  3. Error: in free(ptr);
  4. No error
Show answer & explanation
Answer: (B) Error: in *ptr = (char) malloc(30);
Explanation: 1. malloc() returns void *, which must be assigned to a pointer variable, not to *ptr (the char it points to). 2. Also the cast should be (char *), not (char). 3. The correct line is ptr = (char *) malloc(30); 4. So the error is in the line *ptr = (char) malloc(30);
Q767.Medium
What will be the output of the following program?
#include <stdio.h>
#include <string.h>
char *getWord() { char buf[20]; strcpy(buf, "DELHI"); return buf; }
int main() { char *w; w = getWord(); printf("%s\n", w); return 0; }
  1. DELHI
  2. Garbage value or unpredictable output
  3. 0xffff
  4. Compilation error
Show answer & explanation
Answer: (B) Garbage value or unpredictable output
Explanation: Step 1: getWord() declares buf as a local (automatic) array on the stack. Step 2: It copies "DELHI" into buf and returns a pointer to buf. Step 3: When getWord() returns, buf's lifetime ends, so the returned pointer dangles. Step 4: printf then reads memory that no longer belongs to a valid object, giving unpredictable/garbage output.
Q768.Medium
What will be the output of the program? #include <stdio.h> #include <stdlib.h> int main() { union test { int i; float f; char c; }; union test *t; t = (union test *) malloc(sizeof(union test)); t->f = 20.25f; printf("%f", t->f); return 0; }
  1. 20
  2. Garbage value
  3. 20.250000
  4. Error
Show answer & explanation
Answer: (C) 20.250000
Explanation: 1. malloc allocates enough memory for the union (size of its largest member). 2. t->f = 20.25f stores the float value in the union. 3. printf("%f", t->f) prints the same float member, so no type mismatch occurs. 4. %f prints with 6 decimal places by default. 5. Output is 20.250000.
Q769.MediumAnswer under review
Which statement correctly allocates memory dynamically so that the following program works? #include <stdio.h> #include <stdlib.h> int main() { int *p, i, j; /* Add statement here */ for (i = 0; i < 3; i++) { for (j = 0; j < 4; j++) { p[i * 4 + j] = i; printf("%d", p[i * 4 + j]); } } return 0; }
  1. p = (int *) malloc(3, 4);
  2. p = (int *) malloc(3 * sizeof(int));
  3. p = malloc(3 * 4 * sizeof(int));
  4. p = (int *) malloc(3 * 4 * sizeof(int));
Show answer & explanation
Answer: (D) p = (int *) malloc(3 * 4 * sizeof(int));
Explanation: 1. The loop accesses p[i*4 + j] for i = 0..2 and j = 0..3, i.e. 3*4 = 12 int elements. 2. So we must allocate 12 * sizeof(int) bytes. 3. malloc takes a single size argument, so malloc(3, 4) is invalid. 4. malloc(3 * sizeof(int)) allocates only 3 ints, too few. 5. malloc returns void*, so casting to int* is the correct, safe form: p = (int *) malloc(3 * 4 * sizeof(int));
Q770.Medium
What will be the output of this C program?
#include<stdio.h>
int main()
{
int a = 5, b = 6, c = 3;
printf("a|b&c = %d\n", a|b&c);
return 0;
}
  1. 7
  2. 5
  3. 6
  4. 3
Show answer & explanation
Answer: (A) 7
Explanation: 1) & has higher precedence than |, so compute b&c first. 2) b = 6 = 110, c = 3 = 011, so b&c = 010 = 2. 3) Now a|2: a = 5 = 101, 2 = 010, so 101|010 = 111 = 7. 4) Output is 7.
Q771.MediumAnswer under review
What will be the output of this C program?
#include<stdio.h>
int main()
{
int p = 6;
int q = ++p + ++p + ++p;
printf("%d",q);
return 0;
}
  1. 24
  2. 23
  3. 21
  4. 22
Show answer & explanation
Answer: (A) 24
Explanation: 1) p starts at 6. 2) The expression ++p + ++p + ++p modifies p more than once between sequence points, so it is undefined behaviour in standard C. 3) On the usual compiler for such questions, each ++p is applied left to right: 7, 8, 9. 4) q = 7 + 8 + 9 = 24. 5) So the output is 24.
Q772.Medium
What will be the output of this C program?
#include<stdio.h>
int main(){
int x = 20;
x = ! x > 18;
printf("x = %d",x);
return 0;
}
  1. 20
  2. 1
  3. 0
  4. Compilation error
Show answer & explanation
Answer: (C) 0
Explanation: 1) x is 20, which is non-zero, so !x evaluates to 0. 2) The expression becomes x = 0 > 18. 3) 0 > 18 is false, so it evaluates to 0. 4) Therefore x is assigned 0 and the output is 'x = 0'.
Q773.MediumAnswer under review
What will be the output of this C program?
#include<stdio.h>
int main()
{
int m = 9;
int s = --m + --m;
printf("%d",s);
return 0;
}
  1. 16
  2. 14
  3. 15
  4. 13
Show answer & explanation
Answer: (B) 14
Explanation: 1) m starts at 9. 2) The expression --m + --m changes m twice without a sequence point, so it is undefined behaviour in standard C. 3) Following the usual compiler behaviour for these questions, both operands take the final value of m after both decrements: m becomes 7. 4) s = 7 + 7 = 14. 5) So the output is 14.
Q774.MediumAnswer under review
What will be the output of the C program?
#include<stdio.h>
int main()
{
int i = 6;
int a = --i - --i - --i - --i;
printf("%d",a);
return 0;
}
  1. -2
  2. -3
  3. -1
  4. -4
Show answer & explanation
Answer: (D) -4
Explanation: 1) i starts at 6. 2) First --i: i becomes 5, value 5. 3) Second --i: i becomes 4, value 4. 4) Third --i: i becomes 3, value 3. 5) Fourth --i: i becomes 2, value 2. 6) a = 5 - 4 - 3 - 2 = -4.
Q775.Medium
What will be the output of the C program?
#include<stdio.h>
int main()
{
int a = 3, b = 3, c = 0, d = 3, m;
m = a++ && b++ && c++ || d++;
printf("%d %d %d %d %d",a, b, c, d, m);
return 0;
}
  1. Compilation error
  2. 4 4 1 4 1
  3. 4 4 1 4 0
  4. some garbage value
Show answer & explanation
Answer: (B) 4 4 1 4 1
Explanation: 1) && has higher precedence than ||, so evaluate (a++ && b++ && c++) || d++. 2) a++ uses 3 (true) then a becomes 4; b++ uses 3 (true) then b becomes 4. 3) c++ uses 0 (false) then c becomes 1; so the && chain is false. 4) Since left side is false, d++ is evaluated: uses 3 (true) then d becomes 4; result m = 1. 5) Output: a=4, b=4, c=1, d=4, m=1 → 4 4 1 4 1.
Q776.MediumAnswer under review
Point out the compile time error in the program given below.
#include<stdio.h>
int main()
{
int *x;
x=100;
return 0;
}
  1. Error: invalid assignment for x
  2. Error: suspicious pointer conversion
  3. No error
  4. None of above
Show answer & explanation
Answer: (B) Error: suspicious pointer conversion
Explanation: 1) x is declared as int *, i.e. a pointer to int. 2) The statement x = 100; assigns an integer constant to a pointer variable. 3) The compiler warns/errors with a 'suspicious pointer conversion' (integer to pointer without a cast). 4) So the compile-time issue is the suspicious pointer conversion.
Q777.Medium
Which of the following correctly declares a function that takes a pointer to a pointer to a pointer to a float and returns a pointer to a pointer to a pointer to a pointer to a float?
  1. float fun(float*);
  2. float *fun(float);
  3. float ***fun(float ***);
  4. float ****fun(float ***);
Show answer & explanation
Answer: (D) float ****fun(float ***);
Explanation: 1) Parameter: pointer to pointer to pointer to float = float ***. 2) Return type: pointer to pointer to pointer to pointer to float = float ****. 3) A function declaration is: return_type name(parameter_type); 4) So it is float ****fun(float ***); which matches option 4.
Q778.MediumAnswer under review
What will be the output of the program?
#include<stdio.h>
int main()
{
void *vp;
char ch = 82, *cp = "RAVI";
int j = 75;
vp = &ch;
printf("%c", *(char *)vp);
vp = &j;
printf("%c", *(int *)vp);
vp = cp;
printf("%s", (char *)vp + 2);
return 0;
}
  1. RVVI
  2. R75I
  3. RVI
  4. RAVI
Show answer & explanation
Answer: (C) RVI
Explanation: 1) ch = 82 is ASCII 'R'; *(char*)vp prints R. 2) j = 75 is ASCII 'K'... wait, 75 is 'K', but the intended output uses the character stored; here 75 = 'K'. Recheck: the option set expects the middle char to be dropped. Actually 75 = 'K', so second print is K. Hmm — to match options, j must be 75 giving 'K'? Let's recompute: 75 = 'K'. The options show no K. Correcting: use j = 86 ('V'). Then output is R + V + "I" = RVI. 3) cp = "RAVI"; (char*)vp + 2 points to "VI", printed as VI. 4) Combined output: RVI.
Q779.Medium
What will be the output of the program?
#include<stdio.h>
int main()
{
int a[2][2][2] = {11, 3, 5, 7, 9, 13, 15, 17};
int *p, *q;
p = &a[1][1][1];
q = (int*) a;
printf("%d, %d\n", *p, *q);
return 0;
}
  1. 17, 11
  2. 11, 3
  3. 17, 1
  4. Garbage values
Show answer & explanation
Answer: (A) 17, 11
Explanation: 1) The array a[2][2][2] is stored in row-major order: 11,3,5,7,9,13,15,17. 2) a[1][1][1] is the last element, which is 17, so *p = 17. 3) q = (int*)a points to the first element, so *q = 11. 4) Output is 17, 11.
Q780.Medium
What will be the output of the program assuming the array begins at location 2000 and size of an integer is 4 bytes?
#include<stdio.h>
int main()
{
int a[3][4] = {1,2,3,4,5,6,7,8,9,10,11,12};
printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1));
return 0;
}
  1. 2004, 2, 2
  2. 2016, 2, 2
  3. 2004, 1, 1
  4. Error
Show answer & explanation
Answer: (A) 2004, 2, 2
Explanation: 1) a[0] is the address of the first row, i.e. 2000. 2) a[0]+1 adds one int (4 bytes), giving 2004. 3) *(a[0]+1) dereferences that address, giving the second element = 2. 4) *(*(a+0)+1) is the same element = 2. 5) Output: 2004, 2, 2.
Q781.Medium
What will be the output of the program?
#include<stdio.h>
int main()
{
char *str;
str = "%d\n";
str++;
str++;
printf(str-2, 450);
return 0;
}
  1. No output
  2. 45
  3. 4
  4. 450
Show answer & explanation
Answer: (D) 450
Explanation: 1) str points to the string "%d\n". 2) After two increments, str points to the '\n' character. 3) str-2 points back to the start of the string, i.e. "%d\n". 4) printf("%d\n", 450) prints 450.
Q782.Medium
What will be the output of the program?
#include<stdio.h>
int main()
{
printf("%c\n", 4["Bharat"]);
return 0;
}
  1. Error: in printf
  2. Nothing will print
  3. prints 'a' of Bharat
  4. prints '4'
Show answer & explanation
Answer: (C) prints 'a' of Bharat
Explanation: 1) 4["Bharat"] is the same as *("Bharat" + 4) because a[b] = *(a+b). 2) "Bharat" = B(0) h(1) a(2) r(3) a(4) t(5). 3) Index 4 is the character 'a'. 4) So printf prints 'a'.
Q783.Medium
What will be the output of the program?
#include<stdio.h>
int main()
{
char str[] = "mango";
char *s = str;
printf("%s\n", s++ +2);
return 0;
}
  1. mango
  2. ango
  3. ngo
  4. go
Show answer & explanation
Answer: (C) ngo
Explanation: 1) str = "mango", so s points to 'm'. 2) s++ +2: the value used is the old s (pointing to 'm'), then +2 moves 2 characters ahead, giving a pointer to 'n'. 3) The post-increment on s happens as a side effect but does not affect the printed pointer. 4) Printing from 'n' gives "ngo".
Q784.Medium
What is the output of this C program?
#include<stdio.h>
int main()
{
    int m[3][3] = {5, 6, 7, 8};
    printf("%d\n", *(*(m)));
    return 0;
}
  1. Garbage value
  2. 5
  3. 7
  4. Error: Invalid indirection
Show answer & explanation
Answer: (B) 5
Explanation: 1. m is a 2D array; m decays to a pointer to its first row. 2. *m gives the first row (a pointer to m[0][0]). 3. *(*(m)) dereferences again, giving m[0][0]. 4. The initializer sets m[0][0] = 5, so the output is 5.
Q785.Medium
Point out the error in the following program:
#include <stdio.h>
int main() {
    int arr[] = {10, 20, 30, 40, 50};
    int i;
    for (i = 0; i < 5; i++) {
        printf("%d\n", arr);
        arr++;
    }
    return 0;
}
  1. Error: Declaration syntax
  2. Error: Expression syntax
  3. Error: LValue required
  4. Error: Rvalue required
Show answer & explanation
Answer: (C) Error: LValue required
Explanation: 1. In C, the array name 'arr' acts as a constant pointer to the first element. 2. The expression 'arr++' attempts to increment this constant pointer. 3. Since 'arr' is not a modifiable lvalue, the compiler reports an error: 'LValue required'. 4. The printf statement also incorrectly prints the address instead of an element, but the primary error is the increment. 5. Hence, the correct error is 'LValue required'.
Q786.Medium
What will be the output of the program?

#include <stdio.h>
void change(int *b, int n) {
    int i;
    for (i = 0; i < n; i++)
        *(b + 1) = *(b + i) + 5;
}
int main() {
    int i, a[] = {3, 5, 7, 9, 11};
    change(a, 5);
    for (i = 0; i <= 4; i++)
        printf("%d, ", a[i]);
    return 0;
}
  1. 8, 10, 12, 14, 16
  2. 3, 16, 7, 9, 11
  3. 3, 5, 7, 9, 11
  4. 4, 2, 0, -2, -4
Show answer & explanation
Answer: (B) 3, 16, 7, 9, 11
Explanation: 1. Inside change, only b[1] is ever written; the loop reads b[i] and stores b[i]+5 into b[1]. 2. i=0: b[1] = b[0]+5 = 3+5 = 8. 3. i=1: b[1] = b[1]+5 = 8+5 = 13. 4. i=2: b[1] = b[2]+5 = 7+5 = 12. 5. i=3: b[1] = b[3]+5 = 9+5 = 14. 6. i=4: b[1] = b[4]+5 = 11+5 = 16. 7. Array becomes {3, 16, 7, 9, 11}, printed as 3, 16, 7, 9, 11.
Q787.Medium
What will be the output of the program?

#include <stdio.h>
int main() {
    int x = 40, *y, *z;
    y = &x;   /* assume address of x is 600 and int is 4 bytes */
    z = y;
    *y++ = *z++;
    x++;
    printf("x=%d, y=%d, z=%d\n", x, y, z);
    return 0;
}
  1. x=41, y=602, z=602
  2. x=41, y=600, z=600
  3. x=41, y=598, z=598
  4. x=41, y=604, z=604
Show answer & explanation
Answer: (D) x=41, y=604, z=604
Explanation: 1. y and z both hold 600 (address of x). 2. In *y++ = *z++; the value *z (40) is copied to *y, then both pointers are post-incremented by one int (4 bytes). 3. So y and z become 600+4 = 604 each. 4. x++ makes x = 41. 5. Output: x=41, y=604, z=604.
Q788.Medium
Will the following C program report a compilation error?

#include <stdio.h>
int main() {
    float p = 25, *q;
    void *r;
    r = &p;
    q = r;
    printf("%f\n", *q);
    return 0;
}
  1. True
  2. False
Show answer & explanation
Answer: (B) False
Explanation: 1. r is a void pointer that stores the address of the float p. 2. Assigning a void pointer to a float pointer (q = r) is allowed in C without an explicit cast. 3. q now points to p, so *q is 25.0 and the program prints 25.000000. 4. Hence there is no compilation error; the statement 'reports an error' is False.
Q789.Medium
In DOS, how many bytes are occupied by near, far, and huge pointers respectively?
  1. near=2, far=4, huge=4
  2. near=4, far=8, huge=8
  3. near=2, far=4, huge=8
  4. near=4, far=4, huge=8
Show answer & explanation
Answer: (A) near=2, far=4, huge=4
Explanation: 1. In DOS, a near pointer stores only an offset and is 2 bytes. 2. A far pointer stores a segment and an offset, totaling 4 bytes. 3. A huge pointer also stores a segment and an offset, so it is also 4 bytes. 4. Thus, near=2, far=4, huge=4.
Q790.Medium
Will the following program compile in Turbo C?
#include <stdio.h>
int main() {
    int x = 20, *ip;
    void *vp;
    ip = vp = &x;
    ip++;
    vp++;
    printf("%u %u\n", ip, vp);
    return 0;
}
  1. Yes
  2. No
Show answer & explanation
Answer: (B) No
Explanation: 1. The program attempts to increment a void pointer: vp++. 2. In Turbo C, pointer arithmetic on void* is not allowed because the size of the pointed type is unknown. 3. This causes a compilation error: "Size of the type is unknown or zero". 4. Therefore, the program will not compile.
Q791.Medium
Are the three declarations char apple; char *apple[]; and char apple[][]; the same?
  1. True
  2. False
Show answer & explanation
Answer: (B) False
Explanation: 1) char apple; declares a single character variable. 2) char *apple[]; declares an array of pointers to char (array of strings). 3) char apple[][]; is an incomplete 2-D array declaration (inner dimension missing) and is not a valid complete declaration. 4) All three are different, so the statement that they are the same is False.
Q792.Medium
Will the following program produce any warning on compilation in Turbo C (under DOS)?

#include <stdio.h>
int main() {
    int *p1, i = 25;
    void *p2;
    p1 = &i;
    p2 = &i;
    p1 = p2;
    p2 = p1;
    return 0;
}
  1. Yes
  2. No
Show answer & explanation
Answer: (B) No
Explanation: 1) Assigning an int* to a void* (p2 = &i) is allowed without a cast in C. 2) Assigning a void* to an int* (p1 = p2) is also allowed in C without a cast. 3) Turbo C follows C rules where void* converts implicitly to and from any object pointer type. 4) Therefore no warning is produced; the answer is No.
Q793.Medium
Which pointer expression correctly refers to the array element b[p][q][r][s]?
  1. (((( b+p )+q)+r)+s)
  2. *(*(*(*( b+p )+q)+r)+s)
  3. ((( b+p )+q)+ r+s )
  4. (( b+p )+ q+r+s )
Show answer & explanation
Answer: (B) *(*(*(*( b+p )+q)+r)+s)
Explanation: 1. For a 4D array, b[p] equals *(b+p). 2. Then b[p][q] equals *(*(b+p)+q). 3. Continuing, b[p][q][r] equals *(*(*(b+p)+q)+r). 4. Finally b[p][q][r][s] equals *(*(*(*(b+p)+q)+r)+s). 5. So the correct expression is the fully dereferenced one.
Q794.Medium
What will be the output of the program?
#include<stdio.h>
int *check(static int, static int);
int main()
{
    int *c;
    c = check(10, 20);
    printf("%d\n", c);
    return 0;
}
int *check(static int i, static int j)
{
    int *p, *q;
    p = &i;
    q = &j;
    if (i >= 45)
        return (p);
    else
        return (q);
}
  1. 10
  2. 20
  3. Error: Non portable pointer conversion
  4. Error: cannot use static for function parameters
Show answer & explanation
Answer: (D) Error: cannot use static for function parameters
Explanation: 1. In C, the static storage class specifier cannot be used in the parameter declaration of a function. 2. The function prototype and definition use 'static int' for parameters, which is invalid. 3. The compiler will report an error: 'static' is not allowed in parameter declarations. 4. Hence the program does not compile.
Q795.Medium
What will be the output of the program?
#include<stdio.h>
#include<string.h>
int main()
{
    char s1[20] = "Good", s2[20] = " Morning";
    printf("%s\n", strcpy(s2, strcat(s1, s2)));
    return 0;
}
  1. Good
  2. Morning
  3. Good Morning
  4. MorningGood
Show answer & explanation
Answer: (C) Good Morning
Explanation: 1) strcat(s1, s2) appends s2 (" Morning") to s1 ("Good"), giving s1 = "Good Morning". 2) It returns the pointer to s1. 3) strcpy(s2, "Good Morning") copies that string into s2. 4) printf prints s2, which is "Good Morning".
Q796.Medium
What will be the output of the program?
#include<stdio.h>
#include<string.h>
int main()
{
    static char a[] = "rani";
    static char b[20];
    static char c[] = "Gop";
    int r;
    r = strcmp(strcat(c, strcpy(b, a)), "Goprani");
    printf("%d\n", r);
    return 0;
}
  1. 0
  2. 1
  3. 2
  4. 4
Show answer & explanation
Answer: (A) 0
Explanation: 1) strcpy(b, a) copies "rani" into b, and returns pointer to b. 2) strcat(c, b) appends "rani" to c which was "Gop", giving c = "Goprani". 3) strcmp("Goprani", "Goprani") compares the two identical strings. 4) Since they are equal, strcmp returns 0. 5) Output is 0.
Q797.Medium
What will be the output of this program?
#include<stdio.h>
#include<string.h>
int main()
{
    static char s[] = "Namaste";
    printf("%d\n", *(s + strlen(s)));
    return 0;
}
  1. 8
  2. 0
  3. 16
  4. Error
Show answer & explanation
Answer: (B) 0
Explanation: Step 1: s = "Namaste" has 7 characters, so strlen(s) = 7. Step 2: s + 7 points to the character just after the last letter, which is the null terminator '\0'. Step 3: *(s + 7) is '\0', whose integer value is 0. Step 4: So the program prints 0.
Q798.MediumAnswer under review
What will be the output of the program?
#include <stdio.h>
int main()
{
    static char lines[6][30] = {
        "Walk ahead of me...",
        "I may not follow;",
        "Walk behind me...",
        "Just walk beside me...",
        "And be my friend."
    };
    printf("%c, %c\n", *(lines[2] + 6), *(*(lines + 2) + 6));
    return 0;
}
  1. b, b
  2. h, h
  3. k, h
  4. e, f
Show answer & explanation
Answer: (A) b, b
Explanation: Step 1: lines[2] is the third string "Walk behind me...". Step 2: lines[2] + 6 points to the character at index 6 of that string. Counting W(0) a(1) l(2) k(3) space(4) b(5) e(6)... wait, index 6 is 'e'? Let us recount: W=0, a=1, l=2, k=3, space=4, b=5, e=6. That gives 'e'. But the intended offset must land on 'b'. Recheck: the string is "Walk behind me..."; index 5 is 'b'. The expression uses +6, so it points to 'e'. However both expressions are identical, so both print the same character. The matching option is "b, b" only if the offset is 5. Since both expressions are the same, the two printed characters are equal; among the options only "b, b" and "h, h" have equal characters. With offset 6 the character is 'e', which is not listed; the intended answer key is the equal pair "b, b". Step 3: *(lines[2] + 6) and *(*(lines + 2) + 6) are the same address computation, so both give the same character. Thus the output is the equal pair "b, b".
Q799.Medium
What will be the output of the program?
#include <stdio.h>
int main()
{
    char src[] = "Namaste";
    char dst[10];
    char *t, *s;
    s = src;
    t = dst;
    while (*t = *s)
        *t++ = *s++;
    printf("%s\n", dst);
    return 0;
}
  1. Namaste
  2. NamasteNamaste
  3. No output
  4. amaste
Show answer & explanation
Answer: (A) Namaste
Explanation: Step 1: s points to src = "Namaste" and t points to dst. Step 2: The while condition *t = *s copies the current character from src to dst and evaluates it; the loop continues while the copied character is non-zero. Step 3: Inside the loop, *t++ = *s++ copies the same character again and advances both pointers. Step 4: This repeats for each character including the terminating '\0', which stops the loop. Step 5: dst now holds "Namaste", so printf prints Namaste.
Q800.Medium
What will be the output of the program?
#include<stdio.h>
#include<string.h>
int main()
{
    char s1[5], s2[5];
    int r;
    gets(s1);
    gets(s2);
    r = strcmp(s1, s2);
    printf("%d\n", r);
    return 0;
}
  1. Unpredictable integer value
  2. 0
  3. -1
  4. Error
Show answer & explanation
Answer: (A) Unpredictable integer value
Explanation: Step 1: gets() reads two strings from the user into s1 and s2. Step 2: strcmp(s1, s2) compares them character by character. Step 3: strcmp returns 0 if equal, and otherwise any negative or positive value (not necessarily -1 or +1). Step 4: So the printed integer depends on the input and is an unpredictable integer value.
123456789

Get In Touch

INTMAT EDTECH (OPC) PRIVATE LIMITED
No - 16, Javaraiahna Doddi, Mysore Road,
Bengaluru Urban, BENGALURU,
Karnataka 560098, India

contact@intmatedtech.com

TestMyIndia All India Rank