MCQ Questions

Question Bank › Technical › C › MCQ

123456789

Other questions

Q401.Easy
Does every operator in C have an associativity?
  1. Yes
  2. No
Show answer & explanation
Answer: (A) Yes
Explanation: Associativity (or fixity) decides how operators of the same precedence are grouped when parentheses are absent. Every operator in C is left-associative, right-associative or non-associative, so each one has an associativity. Hence Yes.
Q402.Easy
The associativity of an operator in C is either Left to Right or Right to Left.
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: Associativity tells how operators of the same precedence are grouped when there are no parentheses. In C every operator is either left-associative (e.g. +, -) or right-associative (e.g. =, unary operators). So the statement is True.
Q403.Easy
What will be the output of the program?
#include <stdio.h>
int main()
{
    static int marks[20];
    int k = 0;
    marks[k] = k;
    printf("%d, %d, %d\n", marks[0], marks[1], k);
    return 0;
}
  1. 1, 0, 1
  2. 1, 1, 1
  3. 0, 0, 0
  4. 0, 1, 0
Show answer & explanation
Answer: (C) 0, 0, 0
Explanation: Step 1: static int marks[20]; is a static array, so all its elements are automatically initialised to 0. Step 2: int k = 0; so k is 0. Step 3: marks[k] = k becomes marks[0] = 0, which does not change anything. Step 4: marks[0] = 0, marks[1] = 0 (static default), and k = 0. Step 5: printf prints 0, 0, 0.
Q404.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
    int p = 6, q, r;
    q = --p;
    r = p--;
    printf("%d, %d, %d\n", p, q, r);
    return 0;
}
  1. 6, 5, 5
  2. 6, 5, 4
  3. 4, 5, 5
  4. 5, 5, 4
Show answer & explanation
Answer: (C) 4, 5, 5
Explanation: Step 1: p = 6. Step 2: q = --p is pre-decrement, so p becomes 5 and q = 5. Step 3: r = p-- is post-decrement, so r = 5 and then p becomes 4. Step 4: printf prints p, q, r = 4, 5, 5.
Q405.Easy
What will you do to treat the constant 2.71 as a long double?
  1. use 2.71LD
  2. use 2.71L
  3. use 2.71DL
  4. use 2.71LF
Show answer & explanation
Answer: (B) use 2.71L
Explanation: 1. By default, a floating-point constant like 2.71 is of type double. 2. To make it a long double constant, the suffix L (or l) is appended. 3. So 2.71L is treated as a long double. 4. Suffixes like LD, DL, LF are not valid for this purpose.
Q406.Easy
What will be the output of the program?
#include <stdio.h>
int main() {
    float fval = 8.76;
    printf("%d\n", (int) fval);
    return 0;
}
  1. 0
  2. 0.0
  3. 8.0
  4. 8
Show answer & explanation
Answer: (D) 8
Explanation: 1. fval holds the float value 8.76. 2. The cast (int) fval truncates the fractional part, giving the integer 8. 3. %d prints an integer, so the output is 8. 4. Hence the answer is 8.
Q407.Easy
What will be the output of the program?
#include <stdio.h>
#include <math.h>
int main() {
    printf("%f\n", sqrt(49.0));
    return 0;
}
  1. 7.0
  2. 7
  3. 7.000000
  4. Error: Prototype sqrt() not found.
Show answer & explanation
Answer: (C) 7.000000
Explanation: 1. sqrt(49.0) returns the double value 7.0. 2. The %f format specifier prints a double with 6 digits after the decimal point by default. 3. So 7.0 is printed as 7.000000. 4. Hence the output is 7.000000.
Q408.Easy
Which keyword is used in C to send control (and optionally a value) from a called function back to the calling function?
  1. switch
  2. goto
  3. go back
  4. return
Show answer & explanation
Answer: (D) return
Explanation: 1) The return statement ends execution of the current function. 2) Control goes back to the point where the function was called. 3) It can also send a value back, e.g. return (a+b); in a function returning int. 4) switch and goto are jump statements inside a function; 'go back' is not a C keyword.
Q409.Easy
Is it true that a C function cannot return a floating point value?
  1. Yes, a function cannot return a float
  2. No, a function can return a float
Show answer & explanation
Answer: (B) No, a function can return a float
Explanation: Step 1: In C, a function's return type can be any data type, including float or double. Step 2: Example: float diff(float a, float b) { return a - b; } is perfectly valid. Step 3: Calling diff(7.5, 2.5) returns 5.000000, which can be printed with %f. Step 4: Hence the statement is false; a function can return a floating point number.
Q410.Easy
Must every function in C return a value?
  1. Yes
  2. No
Show answer & explanation
Answer: (B) No
Explanation: Step 1: A function's return type decides whether it returns a value. Step 2: If the return type is declared as void, the function returns nothing. Step 3: Such a void function is perfectly valid in C. Hence not every function must return a value.
Q411.Easy
In C, a function cannot return more than one value at a time using a single return statement.
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: Step 1: A return statement returns exactly one value to the caller. Step 2: After returning, control goes back to the calling function. Step 3: To send multiple results, pointers or a struct must be used, not a single return. So the statement is True.
Q412.Easy
Identify the notation used in each of the following function definitions:
1. int g(int x, float y) { /* some code */ }
2. int g(x, y) int x; float y; { /* some code */ }
  1. K&R Notation 1, ANSI Notation 2
  2. Pre-ANSI C Notation 1, K&R Notation 2
  3. ANSI Notation 1, K&R Notation 2
  4. ANSI Notation 1, Pre-ANSI Notation 2
Show answer & explanation
Answer: (C) ANSI Notation 1, K&R Notation 2
Explanation: Step 1: In definition 1 the parameter types are listed inside the parentheses, which is the ANSI (modern) style. Step 2: In definition 2 the parameter names are inside the parentheses and their types are declared separately before the body, which is the Kernighan and Ritchie (K&R) style. So 1 is ANSI and 2 is K&R.
Q413.Easy
What does the following function compute?

long compute(int n)
{
    int i;
    long r = 1;
    for (i = 1; i <= n; i++)
        r = r * i;
    return r;
}
  1. It computes 1 raised to the power n.
  2. It computes the square root of an integer.
  3. It computes the factorial of an integer.
  4. None of the above
Show answer & explanation
Answer: (C) It computes the factorial of an integer.
Explanation: 1) r starts at 1. 2) The loop runs i from 1 to n, each time doing r = r * i. 3) So r becomes 1*2*3*...*n, which is n! (factorial). 4) Example: n=4 gives r = 1*2*3*4 = 24 = 4!. 5) Therefore the function computes the factorial.
Q414.Easy
In C, if the return type of a function is not explicitly specified, it defaults to int. True or False?
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: 1) In traditional C (C89/C90), a function declared without a return type, e.g. fun(int a), implicitly has return type int. 2) So the statement is True. 3) Note: modern compilers warn about this and C99 onwards discourages implicit int, but the classic rule is that it defaults to int.
Q415.Easy
What will be the output of this program?
#include <stdio.h>
int k;
int greet();
int main() { while (k) { greet(); main(); } printf("Namaste\n"); return 0; }
int greet() { printf("Hi"); }
  1. Namaste
  2. Hi Namaste
  3. No output
  4. Infinite loop
Show answer & explanation
Answer: (A) Namaste
Explanation: 1) k is a global int, so it is zero-initialized to 0. 2) while(k) tests 0, which is false, so the loop body never runs. 3) Control goes to printf("Namaste\n"), which prints Namaste. 4) Output is just Namaste.
Q416.Easy
Is there a fixed limit of 12 on the maximum number of arguments a C function can accept?
  1. Yes
  2. No
Show answer & explanation
Answer: (B) No
Explanation: 1) The C standard does not fix the argument count at 12. 2) Implementations typically allow a much larger number (commonly up to around 127 arguments). 3) Hence the statement is false — answer is No.
Q417.Easy
In C, is it true that every function except main() can be called recursively?
  1. True
  2. False
Show answer & explanation
Answer: (B) False
Explanation: 1) Recursion means a function calls itself. 2) In C there is no restriction that prevents main() from calling itself. 3) So main() can also be recursive; the claim that only non-main functions can recurse is False.
Q418.Easy
In C, a function can be invoked either by passing values or by passing addresses. Which statement is correct?
  1. True — a function may be called by value or by reference
  2. False — C functions can only be called by value
  3. False — C functions can only be called by reference
  4. True — but only for functions returning int
Show answer & explanation
Answer: (A) True — a function may be called by value or by reference
Explanation: 1) Call by value: e.g. res = add(x, y); copies of x and y are passed. 2) Call by reference: e.g. res = add(&x, &y); addresses of x and y are passed and the function uses pointers. 3) Both forms are legal in C, so the statement is True.
Q419.EasyAnswer under review
Will the following code work correctly?
int f1(int a, int b) { return ( f2( 15 ) ); }
int f2(int a) { return (a*a); }
  1. Yes, it returns 225
  2. No, f2 is not declared before use
  3. No, f1 cannot call f2
  4. Yes, it returns 30
Show answer & explanation
Answer: (A) Yes, it returns 225
Explanation: 1) f1 calls f2(15). 2) f2 returns 15*15 = 225. 3) f1 returns that value. 4) With a proper prototype for f2, the code compiles and returns 225.
Q420.Easy
A C function can contain more than one return statement, each returning a different value.
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: 1) A function may have several return statements placed in different branches. 2) Only one executes per call, but each can return a different value. 3) They cannot occur one after another in the same path (code after return is unreachable). 4) Hence the statement is True.
Q421.Easy
In C, a recursive function is generally slower than an equivalent loop because each recursive call consumes extra time and stack space.
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: 1) Each recursive call creates a new stack frame, saving return address and local variables. 2) This costs extra time and memory compared to a simple loop. 3) A loop reuses the same frame, so it is usually faster. 4) Hence the statement is True.
Q422.Easy
When two C source files are compiled and linked together, must the names of functions defined in them be unique across both files?
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: 1. Functions have external linkage by default. 2. The linker combines all object files into one program. 3. If the same function name is defined in two files, the linker reports a multiple definition error. 4. Therefore function names must be unique across files linked together (unless declared static).
Q423.Easy
In C, can too many recursive calls cause a stack overflow?
  1. Yes
  2. No
Show answer & explanation
Answer: (A) Yes
Explanation: 1. Each recursive call stores a return address and local data on the call stack. 2. If recursion goes very deep without a proper base case, stack memory fills up. 3. When the stack is exhausted, a stack overflow error occurs. 4. Hence too many recursive calls can indeed cause stack overflow.
Q424.Easy
In C, is it true that a function can never contain two return statements?
  1. Yes, a function can have only one return statement
  2. No, a function can have multiple return statements in different branches
Show answer & explanation
Answer: (B) No, a function can have multiple return statements in different branches
Explanation: 1. A function may contain more than one return statement. 2. They must not execute one after another in the same path; each return should be in a separate branch. 3. Example: int area(int l, int b){ if(l==0 || b==0){ return 0; } else { return l*b; } } 4. Here two return statements exist but only one executes per call. 5. So the statement 'two return statements should never occur' is false.
Q425.Easy
What will be the output of the program?
#include<stdio.h>
int main()
{
    int a = 375;
    printf("%1d\n", a);
    return 0;
}
  1. 1375
  2. 3
  3. 75
  4. 375
Show answer & explanation
Answer: (D) 375
Explanation: 1. a is an int initialised to 375. 2. In printf("%1d", a) the 1 is a minimum field width, not a truncation. 3. Since 375 needs 3 characters, more than the minimum width 1, the full value is printed. 4. Output is 375.
Q426.Easy
What will be the output of the program if the user types 47 at the prompt?
#include<stdio.h>
int main()
{
    int n;
    printf("%d\n", scanf("%d", &n));
    return 0;
}
  1. 47
  2. 2
  3. 1
  4. 4
Show answer & explanation
Answer: (C) 1
Explanation: 1. scanf returns the number of input items successfully assigned. 2. Here one integer is read into n, so scanf returns 1. 3. The outer printf prints that return value, i.e. 1. 4. The typed value 47 goes into n, not into the output.
Q427.Easy
A text stream is an ordered sequence of characters grouped into lines, where each line consists of zero or more characters followed by a terminating new-line character.
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: Step 1: By definition, a text stream is a sequence of characters organised into lines. Step 2: Each line may contain zero or more characters and ends with a new-line character. Step 3: The last line need not end with a new-line, but the general description holds. Step 4: Therefore the statement is True.
Q428.EasyAnswer under review
What will be the output of the program?
#include <stdio.h>
int main() {
    int n = 5;
    printf("%d == 5 is" "%s\n", n, n == 5 ? "TRUE" : "FALSE");
    return 0;
}
  1. n == 5 is TRUE
  2. 5 == 5 is TRUE
  3. 5 == 5 is FALSE
  4. N == 5 is FALSE
Show answer & explanation
Answer: (B) 5 == 5 is TRUE
Explanation: Step 1: int n = 5; so n holds 5. Step 2: The two string literals "%d == 5 is" and "%s\n" are joined by the compiler into one format string "%d == 5 is%s\n". Step 3: The first argument n is printed with %d, giving 5, so the text becomes "5 == 5 is". Step 4: The condition n == 5 is 5 == 5, which is true, so the ternary gives "TRUE". Step 5: Final output: 5 == 5 is TRUE.
Q429.Easy
In C, what does the mode "rb" mean in the call FILE *fp; fp = fopen("marks.dat", "rb");?
  1. Open "marks.dat" in binary mode for reading
  2. Open "marks.dat" in binary mode for reading and writing
  3. Create a new file "marks.dat" for reading and writing
  4. Open "marks.dat" in text mode for reading
Show answer & explanation
Answer: (A) Open "marks.dat" in binary mode for reading
Explanation: Step 1: In fopen, the first character of the mode string gives the operation: 'r' means read. Step 2: The letter 'b' after 'r' means binary mode (no text translation of newline characters). Step 3: So "rb" = open an existing file in binary mode, read-only. Step 4: Writing is not allowed with "rb", so options mentioning writing or creating are wrong.
Q430.Easy
In C, the offset argument passed to the fseek() function can be a negative number. Is this statement true or false?
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: 1. fseek(FILE *fp, long offset, int origin) repositions the file pointer. 2. The offset is a long integer giving the number of bytes to move. 3. A positive offset moves forward; a negative offset moves backward from the reference position (e.g. SEEK_CUR or SEEK_END). 4. Hence a negative offset is allowed, so the statement is True.
Q431.Easy
What will be the output of the program?
#include<stdio.h>
int main()
{
    float a = 7.26843;
    printf("%2.1f\n", a);
    return 0;
}
  1. 7.00
  2. 7.26
  3. 7.3
  4. 7
Show answer & explanation
Answer: (C) 7.3
Explanation: 1) a is a float initialized to 7.26843. 2) The format %2.1f means minimum width 2 and exactly 1 digit after the decimal point. 3) Rounding 7.26843 to one decimal place gives 7.3. 4) So the output is 7.3.
Q432.Easy
Between gets() and fgets(), which function is safe to use for reading a string into a buffer?
  1. gets()
  2. fgets()
Show answer & explanation
Answer: (B) fgets()
Explanation: 1) gets() reads until newline with no limit on characters, so it can overflow the buffer. 2) fgets(buffer, size, stream) takes the buffer size and reads at most size-1 characters. 3) This bound prevents buffer overflow, making fgets() the safe choice. 4) Hence the answer is fgets().
Q433.Easy
For the standard C string functions (like strlen, strcpy, strcmp) to work safely, the character array must be terminated with a '\0' character.
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: 1) In C a string is a character array ending with the null character '\0'. 2) Functions such as strlen and strcpy scan until they find this '\0'. 3) Without the terminator they read past the array, causing undefined behaviour. 4) So the statement is True.
Q434.Easy
Is the C standard library an actual part of the C language itself?
  1. Yes
  2. No
Show answer & explanation
Answer: (B) No
Explanation: 1. The C standard library is described by the ISO C standard as a set of header files and routines (I/O, string handling, etc.). 2. It is an interface specification, not a built-in part of the language syntax. 3. The actual library implementation is provided separately by the compiler/platform. 4. Hence it is not a part of the C language proper.
Q435.Easy
The itoa function can convert an integer into a string in decimal, octal or hexadecimal form.
  1. Yes
  2. No
Show answer & explanation
Answer: (A) Yes
Explanation: 1. itoa(value, buffer, radix) converts the integer value into a string using the given base (radix). 2. Radix 10 gives decimal, radix 8 gives octal and radix 16 gives hexadecimal. 3. So it can produce decimal, octal or hexadecimal strings, hence Yes.
Q436.Easy
The ftell() function returns the current position of the file pointer in a file stream.
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: 1. ftell() is declared in stdio.h and takes a FILE pointer. 2. It returns the current value of the file-position indicator, i.e. the byte offset from the start of the file. 3. Hence the statement is True.
Q437.EasyAnswer under review
What is stderr in C?
  1. standard error
  2. standard error types
  3. standard error streams
  4. standard error definitions
Show answer & explanation
Answer: (C) standard error streams
Explanation: 1) In C, stdin, stdout and stderr are predefined file pointers (streams). 2) stderr is the standard error stream, the default destination for error messages and diagnostics. 3) Like stdout it is usually directed to the console screen. 4) So stderr is best described as a standard error stream.
Q438.Easy
Data written into a file using fwrite() can be read back using fscanf().
  1. True
  2. False
Show answer & explanation
Answer: (B) False
Explanation: 1) fwrite() performs unformatted (binary) writing of raw bytes to a file. 2) fscanf() performs formatted reading, expecting text that matches format specifiers. 3) Raw binary bytes written by fwrite() do not match the text format fscanf() expects, so they cannot be reliably read back with fscanf(). 4) To read back fwrite() data you should use fread(). Hence the statement is False.
Q439.Easy
In C, a string such as "728" can be converted to an integer using either scanf() or atoi().
  1. Yes
  2. No
Show answer & explanation
Answer: (A) Yes
Explanation: 1) atoi("728") directly returns the integer 728. 2) scanf("%d", &num) reads an integer from input text, effectively converting the string form to int. 3) sscanf(str, "%d", &num) can also convert a given string. 4) So both scanf and atoi can be used, answer is Yes.
Q440.Easy
In C, is there a standard library function available to convert an int or float value into a string?
  1. Yes
  2. No
Show answer & explanation
Answer: (A) Yes
Explanation: 1) C provides sprintf() in stdio.h to write formatted data into a character array. 2) For example, sprintf(buf, "%d", 42) converts the integer 42 into the string "42". 3) Similarly sprintf(buf, "%f", 3.14) converts a float to a string. 4) Hence a function does exist, so the answer is Yes.
Q441.Easy
What does the function gcvt() do in C?
  1. Converts a vector to an integer value
  2. Converts a floating-point number to a string
  3. Converts a 2D array into a 1D array
  4. Converts a multi-dimensional array into a 1D array
Show answer & explanation
Answer: (B) Converts a floating-point number to a string
Explanation: 1. gcvt() is declared in stdlib.h. 2. It takes a floating-point value, a number of significant digits, and a character buffer. 3. It writes the number as a null-terminated string into the buffer. 4. So gcvt() converts a floating-point number to a string.
Q442.Easy
Ravi has a dynamically allocated array in his C program. Can he increase the size of this array after allocation?
  1. Yes
  2. No
Show answer & explanation
Answer: (A) Yes
Explanation: 1. Memory obtained via malloc/calloc can be resized using realloc(). 2. Syntax: ptr = realloc(ptr, new_size); 3. realloc may move the block to a new location and copies old contents. 4. So the size can be increased (or decreased); answer is Yes.
Q443.Easy
Can the size of a statically allocated array (e.g., int a[10];) be increased at runtime in C?
  1. Yes
  2. No
Show answer & explanation
Answer: (B) No
Explanation: Step 1: A statically allocated array has a fixed size determined at compile time. Step 2: Its storage is reserved once and cannot be resized during execution. Step 3: To grow storage at runtime, dynamic allocation (malloc/realloc) must be used instead. Step 4: Hence the answer is No.
Q444.Easy
A program allocates memory dynamically with: int *arr; arr = (int *) malloc(5 * sizeof(int *)); Which call correctly releases this allocated memory?
  1. memfree(arr);
  2. dealloc(arr);
  3. malloc(arr, 0);
  4. free(arr);
Show answer & explanation
Answer: (D) free(arr);
Explanation: Step 1: Memory obtained via malloc() must be released with free(). Step 2: memfree and dealloc are not standard C functions. Step 3: malloc(arr, 0) is not a valid call and does not free memory. Step 4: free(arr) correctly deallocates the block pointed to by arr.
Q445.Easy
When memory is dynamically allocated in C, is there any way to release it during run time?
  1. Yes
  2. No
Show answer & explanation
Answer: (A) Yes
Explanation: 1. Dynamically allocated memory stays reserved until it is explicitly released. 2. The standard library provides free() for exactly this purpose. 3. Calling free(ptr) returns the block pointed to by ptr back to the heap during run time. 4. Therefore the answer is Yes.
Q446.Easy
In C, the malloc() function returns NULL if it fails to allocate the requested amount of memory.
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: Step 1: malloc() attempts to allocate the requested number of bytes. Step 2: If the allocation cannot be satisfied (e.g., insufficient memory), it returns a NULL pointer. Step 3: Hence the statement is True; programmers should always check the returned pointer against NULL.
Q447.Easy
If malloc() successfully allocates memory, it returns the number of bytes it has allocated.
  1. True
  2. False
Show answer & explanation
Answer: (B) False
Explanation: 1. The prototype is void *malloc(size_t size). 2. On success, malloc() returns a pointer to the start of the allocated block, not a byte count. 3. The number of bytes allocated is the size argument the programmer passed in. 4. On failure it returns a NULL pointer. 5. So the statement is False.
Q448.Easy
What will be the output of the C program?
#include<stdio.h>
int main()
{
int val = 12;
printf ("%d %d", val << 1, val >> 1);
return 0;
}
  1. 6 24
  2. 24 6
  3. 13 11
  4. 11 13
Show answer & explanation
Answer: (B) 24 6
Explanation: val=12. Left shift by 1: 12<<1 = 24. Right shift by 1: 12>>1 = 6. printf prints them in order: 24 6.
Q449.Easy
What will be the output of the following C program?
#include<stdio.h>
int main()
{
int arr[8] = {0, 1, 2, 3, 4, 5, 6, 7};
printf("%d", sizeof(arr));
return 0;
}
  1. 2
  2. 4
  3. 16
  4. 32
Show answer & explanation
Answer: (D) 32
Explanation: 1. arr is an array of 8 integers. 2. Assuming sizeof(int) = 4 bytes (typical), total size = 8 * 4 = 32 bytes. 3. sizeof(arr) returns the total size in bytes, which is 32. 4. Hence output is 32.
Q450.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
int a = 6, b = 3;
printf("a^b = %d", a^b);
return 0;
}
  1. 5
  2. 6
  3. 9
  4. 3
Show answer & explanation
Answer: (A) 5
Explanation: 1) a = 6 = 110 in binary. 2) b = 3 = 011 in binary. 3) XOR gives 1 only when bits differ: 110^011 = 101. 4) 101 in decimal is 5, so output is 5.
Q451.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
int a = 5, b = 3;
printf("a|b = %d\n", a|b);
return 0;
}
  1. 7
  2. 6
  3. 8
  4. 5
Show answer & explanation
Answer: (A) 7
Explanation: 1) a = 5 = 101 in binary. 2) b = 3 = 011 in binary. 3) Bitwise OR gives 1 where either bit is 1: 101|011 = 111. 4) 111 in decimal is 7, so output is 7.
Q452.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
int p[3] = {'\0', '\0'};
int q[3] = {'\0', '\0'};
int d = p[2] + q[1];
printf("%d", d);
return 0;
}
  1. Compilation error
  2. 0
  3. No Output
  4. some garbage value
Show answer & explanation
Answer: (B) 0
Explanation: 1) Arrays p and q are partially initialized with two '\0' (value 0) elements each. 2) The remaining element is automatically set to 0. 3) So p[2] = 0 and q[1] = 0. 4) d = 0 + 0 = 0. 5) printf prints 0.
Q453.Easy
Will the following program compile successfully?
#include <stdio.h>
int main() {
    char name[6] = "Rahul";
    return 0;
}
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: 1. The array 'name' is declared with size 6. 2. The string literal "Rahul" has 5 characters plus a null terminator, totaling 6 characters. 3. The initializer exactly fits the array size, so it is valid. 4. C does not perform bounds checking at compile time, but even if it did, this is within bounds. 5. Therefore, the program compiles without error.
Q454.EasyAnswer under review
What will be the output of this C program?
#include<stdio.h>
int main()
{
int v = NULL - true;
printf("%d", v);
return 0;
}
  1. Compilation error
  2. 1
  3. -1
  4. Runtime error
Show answer & explanation
Answer: (C) -1
Explanation: 1. NULL is defined as 0. 2. true is defined as 1 (from stdbool.h). 3. So v = 0 - 1 = -1. 4. printf prints -1.
Q455.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
printf("%d", 4 * 3--);
return 0;
}
  1. 4
  2. 12
  3. 9
  4. Compilation error
Show answer & explanation
Answer: (D) Compilation error
Explanation: 1. The expression '3--' tries to apply the decrement operator to a constant. 2. The -- operator needs a modifiable lvalue, but 3 is a literal constant. 3. The compiler rejects this, so it is a compilation error.
Q456.Easy
In C, consider the two declarations: char *p = 0; and char *q = NULL; Is there any difference between these two statements?
  1. Yes, they are different
  2. No, they are the same
Show answer & explanation
Answer: (B) No, they are the same
Explanation: 1) In C, NULL is a macro defined (typically in stdio.h/stddef.h) as 0 (or (void*)0). 2) So char *q = NULL; is effectively char *p = 0;. 3) Both p and q become null pointers pointing to nothing. 4) Hence there is no difference between the two statements.
Q457.Easy
What is (void*)0 ?
  1. Representation of NULL pointer
  2. Representation of void pointer
  3. Error
  4. None of the above
Show answer & explanation
Answer: (A) Representation of NULL pointer
Explanation: 1) The integer constant 0 cast to void* is the standard null pointer constant. 2) It represents a pointer that points to no valid memory, i.e., NULL. 3) Hence (void*)0 is the representation of a NULL pointer.
Q458.Easy
Are the expressions *ptr++ and ++*ptr the same?
  1. True
  2. False
Show answer & explanation
Answer: (B) False
Explanation: 1) *ptr++ first uses the value *ptr, then increments the pointer ptr (pointer moves to next element). 2) ++*ptr increments the value pointed to by ptr (the data), pointer itself unchanged. 3) Since one changes the pointer and the other changes the pointed value, they are not the same.
Q459.Easy
Is the following a correct way to assign a NULL pointer in C?
int i = 0;
char *q = (char*) i;
  1. Yes
  2. No
Show answer & explanation
Answer: (B) No
Explanation: 1. Here i is an int variable holding 0, and we cast the integer value 0 to char*. 2. Casting an int variable to a pointer is not the standard way to get a NULL pointer and may warn or behave unexpectedly. 3. The correct way is to assign the constant 0 directly: char *q = 0; or char *q = (char*)0; or char *q = NULL; 4. Therefore the given code is not the correct way, so the answer is No.
Q460.Easy
If the size of an int is 4 bytes, what will be the output of the program?

#include <stdio.h>
int main() {
    int arr[] = {21, 22, 23, 24, 25};
    printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
    return 0;
}
  1. 10, 2, 4
  2. 20, 4, 4
  3. 16, 2, 2
  4. 20, 2, 2
Show answer & explanation
Answer: (B) 20, 4, 4
Explanation: 1. arr has 5 ints, each 4 bytes, so sizeof(arr) = 5 x 4 = 20. 2. *arr is the first element (an int), so sizeof(*arr) = 4. 3. arr[0] is also an int, so sizeof(arr[0]) = 4. 4. Output: 20, 4, 4.
Q461.Easy
Is a NULL pointer the same as an uninitialized pointer?
  1. Yes
  2. No
Show answer & explanation
Answer: (B) No
Explanation: 1. A NULL pointer explicitly points to nothing (address 0). 2. An uninitialized pointer contains an indeterminate address (garbage). 3. They are not the same; dereferencing either is unsafe, but NULL is a defined value. 4. Therefore, the answer is No.
Q462.Easy
In which header file is the NULL macro defined?
  1. stdio.h
  2. stddef.h
  3. stdio.h and stddef.h
  4. math.h
Show answer & explanation
Answer: (C) stdio.h and stddef.h
Explanation: 1. The NULL macro is defined in several standard headers. 2. Both stdio.h and stddef.h define NULL. 3. Therefore, the correct option is "stdio.h and stddef.h".
Q463.EasyAnswer under review
Consider the declaration: char **k;  Which of the following statements is correct about k?
  1. k is a pointer to a pointer to a pointer to a char
  2. k is a pointer to a pointer to a pointer to a pointer to a char
  3. k is a pointer to a char pointer
  4. k is a pointer to a pointer to a char
Show answer & explanation
Answer: (D) k is a pointer to a pointer to a char
Explanation: 1) Read the declaration from the identifier outward: char **k means k is a pointer (*). 2) The second * means that pointer points to another pointer. 3) That second pointer points to a char. 4) So k is a pointer to a pointer to a char.
Q464.Easy
In C, a pointer is:
  1. A keyword used to declare variables
  2. A variable that stores the address of an instruction
  3. A variable that stores the address of another variable
  4. All of the above
Show answer & explanation
Answer: (C) A variable that stores the address of another variable
Explanation: 1. A pointer is a special variable whose value is a memory address. 2. Typically it holds the address of another variable (e.g., int *p = &x;). 3. It is not a keyword, and it stores data addresses, not instruction addresses. 4. Hence the correct statement is: a variable that stores the address of another variable.
Q465.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
    char *fmt;
    fmt = "%d";
    printf(fmt, 42);
    return 0;
}
  1. Error
  2. No output
  3. 42
  4. %d
Show answer & explanation
Answer: (C) 42
Explanation: 1. fmt is a char pointer holding the string "%d". 2. printf(fmt, 42) is equivalent to printf("%d", 42). 3. The format specifier %d prints the integer 42. 4. So the output is 42.
Q466.Easy
Which statement will you add to the following program to ensure that the program outputs "Bharat" on execution?
#include<stdio.h>
int main()
{
    char s[] = "Bharat";
    char t[25];
    char *ps, *pt;
    ps = s;
    pt = t;
    while (*ps)
        *pt++ = *ps++;
    /* Add a statement here */
    printf("%s\n", t);
    return 0;
}
  1. *pt = '';
  2. pt = '\0';
  3. *pt = '\n';
  4. *pt = '\0';
Show answer & explanation
Answer: (D) *pt = '\0';
Explanation: 1. The while loop copies characters from s to t until the null terminator of s is reached. After the loop, pt points to the position in t where the next character would be written. 2. To make t a valid string, we must append a null terminator at that position. 3. The correct statement is *pt = '\0'; which stores the null character at the current position of pt. 4. Other options are invalid: *pt = ''; is a syntax error, pt = '\0'; assigns a char to a pointer, *pt = '\n'; adds a newline instead of null terminator.
Q467.Easy
Which of the following functions sets the first n characters of a string to a given character?
  1. strinit()
  2. strnset()
  3. strset()
  4. strcset()
Show answer & explanation
Answer: (B) strnset()
Explanation: 1) strnset(char *s, int ch, size_t n) replaces the first n characters of string s with the character ch. 2) strset() sets ALL characters (not just first n) to a given character. 3) strinit() and strcset() are not standard library functions. 4) Hence the function that sets the first n characters is strnset().
Q468.Easy
Which of the following statements is correct about the program below?
#include<stdio.h>
int main()
{
    char name[20], *p;
    printf("Enter a name\n");
    scanf("%s", name);
    p = name;
    while(*p != '\0')
    {
        if(*p >= 97 && *p <= 122)
            *p = *p - 32;
        p++;
    }
    printf("%s", name);
    return 0;
}
  1. The code converts a string into an integer
  2. The code converts lower case characters to upper case
  3. The code converts upper case characters to lower case
  4. There is an error in the code
Show answer & explanation
Answer: (B) The code converts lower case characters to upper case
Explanation: 1) ASCII codes 97 to 122 are the lowercase letters a-z. 2) For each such character, the code subtracts 32, which maps it to the uppercase letter (e.g., 'a'=97 becomes 'A'=65). 3) Other characters (uppercase, digits, symbols) are left unchanged. 4) So the program converts lowercase letters of the input to uppercase.
Q469.EasyAnswer under review
What will be the output of the program?
#include<stdio.h>
#include<string.h>
int main()
{
    char city[] = "Mumbai\0\BXYZ\0";
    printf("%d\n", strlen(city));
    return 0;
}
  1. 10
  2. 6
  3. 5
  4. 11
Show answer & explanation
Answer: (C) 5
Explanation: 1) The array holds the characters M,u,m,b,a,i then a '\0' (null terminator), followed by more characters that are ignored by string functions. 2) strlen counts characters up to (but not including) the first '\0'. 3) 'Mumbai' has 6 letters, but here the string is 'Mumbai'? Wait: the literal is "Mumbai" = 6 characters. Let us recount: M-u-m-b-a-i = 6. 4) So strlen returns 6, not 5. Correcting: the first '\0' comes after 6 characters, so strlen = 6. 5) Answer is 6.
Q470.Easy
What will be the output of the program?
#include <stdio.h>
int main()
{
    char s[] = "%d\n";
    s[1] = 'c';
    printf(s, 66);
    return 0;
}
  1. A
  2. B
  3. c
  4. 66
Show answer & explanation
Answer: (B) B
Explanation: Step 1: char s[] = "%d\n" initializes the array to the characters '%', 'd', '\n', '\0'. Step 2: s[1] = 'c' replaces 'd' with 'c', so the array becomes "%c\n". Step 3: printf(s, 66) is equivalent to printf("%c\n", 66). Step 4: ASCII value 66 corresponds to the character 'B'. So the output is B.
Q471.Easy
If the two strings passed to the strcmp() function are identical, then strcmp() returns
  1. -1
  2. 1
  3. 0
  4. Yes
Show answer & explanation
Answer: (C) 0
Explanation: 1) Declaration: int strcmp(const char *s1, const char *s2); 2) If s1 < s2 it returns a value < 0. 3) If s1 > s2 it returns a value > 0. 4) If s1 == s2 (identical strings) it returns 0.
Q472.Easy
What will be the output of the program?
#include<stdio.h>
int main()
{
    char word = "Namaste";
    printf("%s\n", word);
    return 0;
}
  1. Error
  2. Namaste
  3. Base address of word
  4. No output
Show answer & explanation
Answer: (A) Error
Explanation: 1) word is declared as a single char, but it is initialized with a string literal "Namaste". 2) A string literal is a pointer (char*), assigning it to a char causes a non-portable pointer conversion error. 3) To fix, use char *word = "Namaste"; or char word[] = "Namaste"; 4) As written, the program gives an error.
Q473.Easy
What will be the output of the program?
#include<stdio.h>
#include<string.h>
int main()
{
    char line[100];
    int i;
    printf("Enter a line of text\n");
    gets(line);
    for(i = strlen(line) - 1; i >= 0; i--)
        putchar(line[i]);
    return 0;
}
If the user enters: Namaste Bharat
  1. Namaste Bharat
  2. tarahB etsamaN
  3. Namaste
  4. None of above
Show answer & explanation
Answer: (B) tarahB etsamaN
Explanation: 1) gets() reads the whole line 'Namaste Bharat' into line. 2) strlen(line) = 14, so i starts at 13. 3) The loop prints characters from index 13 down to 0, i.e. in reverse order. 4) Reversed string is 'tarahB etsamaN'.
Q474.Easy
Which of the following statements about strings in C are correct?
1. A string is a collection of characters terminated by '\0'.
2. The format specifier %s is used to print a string.
3. The length of a string can be obtained using strlen().
4. A pointer cannot be used to work with strings.
  1. 1, 2
  2. 1, 2, 3
  3. 2, 4
  4. 3, 4
Show answer & explanation
Answer: (B) 1, 2, 3
Explanation: Step 1: Statement 1 is true: a C string is a char array ending with the null character '\0'. Step 2: Statement 2 is true: %s in printf prints a string. Step 3: Statement 3 is true: strlen() returns the length excluding the '\0'. Step 4: Statement 4 is false: pointers can point to strings, e.g. char *p = "Bharat"; Step 5: Hence only 1, 2 and 3 are correct.
Q475.Easy
What will be the output of the program?
#include<stdio.h>
#include<string.h>
int main()
{
    printf("%d\n", strlen("987654"));
    return 0;
}
  1. 6
  2. 12
  3. 7
  4. 2
Show answer & explanation
Answer: (A) 6
Explanation: Step 1: strlen counts the characters in the string, excluding the terminating '\0'. Step 2: The string "987654" has the characters 9,8,7,6,5,4. Step 3: That is 6 characters, so strlen returns 6. Step 4: The program prints 6.
Q476.EasyAnswer under review
What will be the output of the following C program?
#include <stdio.h>
#include <string.h>
int main() {
    printf("%c\n", "kolkata"[3]);
    return 0;
}
  1. Error
  2. k
  3. kata
  4. o
Show answer & explanation
Answer: (D) o
Explanation: 1) "kolkata" is a string literal; in the expression it decays to a pointer to its first character. 2) The subscript [3] accesses the character at index 3 (0-based): k(0) o(1) l(2) k(3) a(4) t(5) a(6). 3) Wait—index 3 is 'k'. Recheck: k=0, o=1, l=2, k=3, a=4, t=5, a=6. So "kolkata"[3] is 'k'. 4) Correcting the option set: the character at index 3 of "kolkata" is 'k'. 5) Hence the output is: k
Q477.Easy
Which of the following statements about the C library function strcmp(s1, s2) is correct?
  1. strcmp(s1, s2) returns a value less than 0 if s1 > s2
  2. strcmp(s1, s2) returns a value greater than 0 if s1 < s2
  3. strcmp(s1, s2) returns 0 if s1 == s2
  4. strcmp(s1, s2) always returns 1 if s1 == s2
Show answer & explanation
Answer: (C) strcmp(s1, s2) returns 0 if s1 == s2
Explanation: 1) strcmp compares strings character by character. 2) If s1 is lexicographically less than s2, it returns a value < 0. 3) If s1 is greater than s2, it returns a value > 0. 4) If both strings are identical, it returns exactly 0. 5) So the only correct statement is: returns 0 if s1 == s2.
Q478.Easy
What will be the output of the following C program?
#include <stdio.h>
int main()
{
    char str[] = "Chennai\0\Goa\0";
    printf("%s\n", str);
    return 0;
}
  1. Goa
  2. Chennai
  3. Chennai Goa
  4. Chennai\0Goa
Show answer & explanation
Answer: (B) Chennai
Explanation: 1. A C string is a sequence of characters ending at the first null character '\0'. 2. The array str is initialised with "Chennai\0\Goa\0"; the first '\0' appears right after "Chennai". 3. printf("%s", str) prints characters starting at str until it meets the first '\0'. 4. So only "Chennai" is printed; the rest of the array is ignored.
Q479.Easy
Which of the following C library functions is used to find the first occurrence of a given substring inside another string?
  1. strchr()
  2. strrchr()
  3. strstr()
  4. strnset()
Show answer & explanation
Answer: (C) strstr()
Explanation: 1. strchr() finds the first occurrence of a single character in a string. 2. strrchr() finds the last occurrence of a single character in a string. 3. strnset() fills the first n characters of a string with a given character. 4. strstr(s1, s2) returns a pointer to the first occurrence of the substring s2 inside s1, so it is the correct function.
Q480.Easy
Which of the following C functions is most appropriate for reading a multi-word string (a line containing spaces) from the user?
  1. printf()
  2. scanf()
  3. gets()
  4. puts()
Show answer & explanation
Answer: (C) gets()
Explanation: 1. scanf() with %s stops reading at the first whitespace, so it cannot read a full multi-word line. 2. printf() and puts() are output functions, not input functions. 3. gets() reads characters from stdin until a newline is encountered, so it captures spaces and multiple words. 4. Therefore gets() is the appropriate function for reading a multi-word string.
Q481.Easy
What will be the output of the following C program?
#include <stdio.h>
int main()
{
    printf("Bharat", "Delhi\n");
    return 0;
}
  1. Error
  2. Bharat Delhi
  3. Bharat
  4. Delhi
Show answer & explanation
Answer: (C) Bharat
Explanation: 1. printf takes a format string as its first argument: "Bharat". 2. The format string has no conversion specifiers (like %s or %d), so the extra argument "Delhi\n" is simply ignored. 3. The comma operator evaluates left to right but only the format string is used for printing. 4. Hence the program prints Bharat and then terminates.
Q482.Easy
A union cannot be nested inside a structure.
  1. True
  2. False
Show answer & explanation
Answer: (B) False
Explanation: 1. C allows a union to be declared as a member of a structure. 2. Example: struct S { int a; union U { int x; float y; } u; }; compiles fine. 3. Similarly a structure can be nested inside a union. 4. Hence the statement is False.
Q483.Easy
In C, the members of a union can be of different data types and sizes.
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: 1. A union is a user-defined data type in C. 2. All members of a union share the same memory location. 3. The size of the union is the size of its largest member. 4. Members can be of different types (e.g., int, float, char array) and different sizes. 5. Hence the statement is True.
Q484.Easy
Point out the error, if any, in the following declaration:
struct student
{
    int rollno;
    struct student *next;
};
  1. Error: in structure declaration
  2. Linker Error
  3. No Error
  4. None of the above
Show answer & explanation
Answer: (C) No Error
Explanation: 1. The structure 'student' contains a member 'next' that is a pointer to struct student. 2. A pointer to an incomplete type is allowed inside the structure being defined, because only the pointer's size is needed. 3. Such a declaration is called a self-referential structure and is valid C. 4. Therefore there is no error.
Q485.Easy
In C, one of the elements of a structure can be a pointer to the same structure type.
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: 1. A structure may contain a pointer to its own type, e.g. struct node { int data; struct node *next; }; 2. The pointer only stores an address, so its size is known at compile time. 3. This does not create an infinitely large structure, so it is legal. 4. Such self-referential structures are the basis of linked lists and trees.
Q486.Easy
The '->' operator in C is used to access members of a structure through a pointer to that structure.
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: 1. If p is a pointer to a structure, then p->member accesses that member. 2. It is equivalent to (*p).member. 3. So the '->' operator works with a pointer to a structure variable. 4. Therefore the statement is True.
Q487.Easy
Can a structure in C contain a pointer to a structure of its own type?
  1. Yes
  2. No
Show answer & explanation
Answer: (A) Yes
Explanation: 1. A structure member can be a pointer to the same structure type. 2. Example: struct Node { int data; struct Node *next; }; is valid. 3. Such structures are called self-referential structures and are used in linked lists and trees. 4. Therefore the answer is Yes.
Q488.Easy
What will be the output of the following C program?

#include <stdio.h>

struct book {
    int id;
    char title[25];
};

int main() {
    struct book b[] = {
        {101, "Python"},
        {102, "Java"},
        {103, "C++"}
    };
    printf("%d ", b[1].id);
    printf("%s\n", (*(b+2)).title);
    return 0;
}
  1. 102 Java
  2. 101 Python
  3. 102 C++
  4. 103 C++
Show answer & explanation
Answer: (C) 102 C++
Explanation: The array b has three elements. b[1] is the second element, so b[1].id is 102. (*(b+2)) is equivalent to b[2], so its title is "C++". Thus the output is "102 C++".
Q489.Easy
What is the similarity between a structure, union and enumeration?
  1. All of them let you define new values
  2. All of them let you define new data types
  3. All of them let you define new pointers
  4. All of them let you define new structures
Show answer & explanation
Answer: (B) All of them let you define new data types
Explanation: Structures, unions, and enumerations are all used to create new data types in C. A structure groups different data types, a union holds one of several data types, and an enumeration defines a set of named integer constants. They do not define new values, pointers, or structures (though structures can contain other structures). Thus, the correct similarity is that they define new data types.
Q490.Easy
Consider the following C program:
#include <stdio.h>
struct employee {
    int empId;
    int deptNo;
    int salary;
};
int main() {
    struct employee e;
    struct employee *ptr;
    ptr = &e;
    return 0;
}
Which of the following correctly assigns 12 to the deptNo member using the pointer variable ptr?
  1. ptr.deptNo = 12
  2. &ptr.deptNo = 12
  3. e.deptNo = 12
  4. ptr->deptNo = 12
Show answer & explanation
Answer: (D) ptr->deptNo = 12
Explanation: 1. ptr is a pointer to struct employee, so to access a member through the pointer we use the arrow operator (->). 2. The correct syntax is ptr->deptNo = 12. 3. Option A is wrong because ptr is not a structure variable; dot requires a structure. 4. Option B is invalid because &ptr.deptNo is not an lvalue. 5. Option C uses the structure variable e directly, not the pointer, so it does not use ptr.
Q491.Easy
Consider the C statement: car.body.door = 4; Which statement is correct about this code?
  1. Structure door is nested within structure body.
  2. Structure body is nested within structure car.
  3. Structure car is nested within structure body.
  4. Structure car is nested within structure door.
Show answer & explanation
Answer: (B) Structure body is nested within structure car.
Explanation: 1. The access chain is car.body.door, read left to right. 2. car is the outermost structure variable. 3. body is a member of car, so structure body is nested inside structure car. 4. door is a member of body, so door is nested inside body (not directly in car). 5. Therefore the correct statement is that body is nested within car.
Q492.Easy
In C, a structure can be defined inside another structure (nested structure).
  1. True
  2. False
Show answer & explanation
Answer: (A) True
Explanation: 1) C allows a struct member to itself be a struct type. 2) Example: struct date { int d, m, y; }; struct student { char name[20]; struct date dob; }; is valid. 3) The inner struct can be declared separately or directly inside the outer one. 4) Therefore the statement is True.
Q493.Easy
In C, can a union contain a pointer as one of its members?
  1. Yes, a union can have a pointer member
  2. No, a union cannot contain a pointer
  3. Only if the union has a single member
  4. Only if the pointer is declared as void *
Show answer & explanation
Answer: (A) Yes, a union can have a pointer member
Explanation: 1. A union is a user-defined type whose members share the same memory location. 2. The C standard does not restrict the types of members a union may hold. 3. A pointer is just another object type, so it is allowed as a union member. 4. Hence a union containing a pointer can be created; the statement that it cannot is false.
Q494.Easy
In C, is there an easy built-in way to print the symbolic name of an enumeration value (for example, printing "RED" instead of 0)?
  1. Yes, printf with %s on the enum variable prints the name
  2. Yes, the compiler automatically stores the names as strings
  3. No, you must write your own function that maps each enum constant to a string
  4. Yes, using the # operator on the enum variable
Show answer & explanation
Answer: (C) No, you must write your own function that maps each enum constant to a string
Explanation: 1) In C, an enum constant is just an integer; the names exist only at compile time. 2) The compiled program stores only the numeric values, not the identifiers. 3) So printf cannot recover the name from the value. 4) The usual workaround is a helper function or array of strings that maps each value to its name.
Q495.Easy
In C, which operator is used to access a member of a structure through a structure variable (not a pointer)?
  1. The dot operator (.)
  2. The arrow operator (->)
  3. The scope resolution operator (::)
  4. The address-of operator (&)
Show answer & explanation
Answer: (A) The dot operator (.)
Explanation: 1. For a structure variable, members are accessed using the dot operator, e.g., s.name. 2. The arrow operator (->) is used with a pointer to a structure, e.g., p->name. 3. :: is not a C operator (it is C++ scope resolution). 4. & gives the address, not member access. 5. So the correct operator is the dot (.).
Q496.Easy
Is the following declaration acceptable in C?
typedef long no, *ptrtono;
no n;
ptrtono p;
  1. Yes
  2. No
Show answer & explanation
Answer: (A) Yes
Explanation: A single typedef can declare multiple names. Here 'no' becomes an alias for 'long', and 'ptrtono' becomes an alias for 'long *'. So 'no n;' declares a long variable, and 'ptrtono p;' declares a pointer to long. The declaration is valid C.
Q497.Easy
What will be the output of this C program?
#include<stdio.h>
int main()
{
    enum fruit{mango, apple, banana};
    typedef enum fruit myfruit;
    myfruit f = mango;
    printf("%d", f);
    return 0;
}
  1. 1
  2. 0
  3. 2
  4. mango
Show answer & explanation
Answer: (B) 0
Explanation: In an enum, the first enumerator gets value 0 unless assigned otherwise. So mango = 0, apple = 1, banana = 2. The variable f is assigned mango, i.e. 0. printf("%d", f) prints the integer value 0. Hence the output is 0.
Q498.Easy
In the following code, is p2 an integer pointer or an integer?
typedef int * iptr;
iptr p1, p2;
  1. Integer
  2. Integer pointer
  3. Error in declaration
  4. None of above
Show answer & explanation
Answer: (B) Integer pointer
Explanation: 1) typedef int * iptr makes iptr a complete type meaning 'pointer to int'. 2) In 'iptr p1, p2;' both p1 and p2 are declared with the same type iptr. 3) Unlike a #define, the * is not re-substituted per variable. 4) Therefore both p1 and p2 are integer pointers.
Q499.Easy
What will be the output of the program?
#include <stdio.h>
int main() {
    typedef int arr[5];
    arr marks = {10, 20, 30, 40, 50};
    int i;
    for (i = 0; i < 4; i++)
        printf("%d,", marks[i]);
    return 0;
}
  1. 10,20,30,40,
  2. 10,20,30,40,50,
  3. No output
  4. Error: Cannot use typedef with an array
Show answer & explanation
Answer: (A) 10,20,30,40,
Explanation: 1) typedef int arr[5] makes arr an alias for an array of 5 ints. 2) marks is initialised to {10,20,30,40,50}. 3) The loop runs for i = 0,1,2,3 (i < 4), so it prints marks[0] to marks[3]. 4) Output is 10,20,30,40, with a trailing comma and no newline.
Q500.Easy
In the following code, are the properties of i, j and x, y the same?
typedef unsigned long int uli;
uli i, j;
unsigned long int x, y;
  1. Yes
  2. No
Show answer & explanation
Answer: (A) Yes
Explanation: Step 1: typedef unsigned long int uli; makes uli an alias for unsigned long int. Step 2: uli i, j; therefore declares i and j as unsigned long int. Step 3: unsigned long int x, y; declares x and y with exactly the same type. Step 4: Since the underlying types are identical, their properties are the same.
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