The document contains 50 multiple choice questions related to C programming. The questions cover a variety of topics including data types, operators, control flow, functions, pointers, arrays, structures and preprocessor directives. Sample questions include the meaning of literal and coercion, output of code snippets involving operators like ++ and =, and standard C functions like printf and scanf.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
989 views
C Questions
The document contains 50 multiple choice questions related to C programming. The questions cover a variety of topics including data types, operators, control flow, functions, pointers, arrays, structures and preprocessor directives. Sample questions include the meaning of literal and coercion, output of code snippets involving operators like ++ and =, and standard C functions like printf and scanf.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12
OBJECTIVE TYPE QUESTIONS
Q.1 Literal means
(A) a string. (B) a string constant. (C) a character. (D) an alphabet. Ans:B
Q.2 Choose the correct answer (A) Casting refers to implicit type conversion. (B) Coercion refers to implicit type conversion. (C) Casting means coercion. (D) Coercion refers to explicit type conversion. Ans:B
Q.3 printf (%d, printf (tim)); (A) results in a syntax error (B) outputs tim3 (C) outputs garbage (D) outputs tim and terminates abruptly Ans:B printf statement will print tim3, tim due to inner printf statement and 3 as length due to outer printf statement.
Q.4 Output of the following program fragment is x = 5; y = x++; printf(%d%d, x, y); (A) 5, 6 (B) 5, 5 (C) 6, 5 (D) 6, 6 Ans:C x is incremented by 1 and before that increment the value is assigned to y so value of x=6 and y=5.
Q.5 The value of an automatic variable that is declared but not initialised will be (A) 0 (B) -1 (C) unpredictable (D) none of these Ans:C
Q.6 Consider the following program main ( ) { float a = 0.5, b = 0.7; if (b < 0.8) if (a < 0.5) printf (ABCD); else printf (PQR); else printf (JKLF); } The output is (A) ABCD (B) PQR (C) JKLF (D) None of these Ans:B Since b=0.7<0.8, the control goes to second if statement where (a<0.5) is false to printf statement in else part executed printing PQR
Q.7 The following program fragment int *a; *a = 7; (A) assigns 7 to a (B) results in compilation error (C) assigns address of a as 7 (D) segmentation fault Ans:D
Q.8 A pointer variable can be (A) passed to a function as argument. (B) changed within function. (C) returned by a function. (D) assigned an integer value. Ans:C
Q.9 C is often called a (A) Object oriented language (B) High level language (C) Assembly language (D) Machine level language Ans:B
Q.10 The loop in which the statements within the loop are executed at least once is called (A) do-while (B) while (C) for (D) goto Ans:A
Q.11 The control automatically passes to the first statement after the loop in (A) continue statement (B) break statement (C) switch statement (D) if statement Ans:B
Q.12 A self contained block of statements that perform a coherent task of some kind is called a (A) Monitor (B) Function (C) Program (D) Structure Ans:B
Q.13 Recursion is sometimes called (A) Circular definition (B) Complex definition (C) Procedure (D) Union Ans:A
Q.14 Unsigned integer occupies (A) Two bytes (B) Four bytes (C) One byte (D) Eight bytes Ans:B
Q.15 Each C preprocessor directive begins with (A) # (B) include (C) main() (D) { Ans:A
Q.16 main() { long i = 30000; printf(%d, i); } the output is (A) 3000 (B) 30000 (C) 0 (D) -1 Ans:B
Q.17 The directive that can be used to test whether an expression evaluates to a nonzero value or not is (A) #if (B) #elif (C) #endif (D) #exit Ans:A
Q.18 main() { printf(%p\n, main()); } (A) Prints the address of main function. (B) Prints 0. (C) Is an error. (D) Is an infinite loop. Ans:A
Q.19 The << operator is used for (A) Right shifting (B) Left shifting (C) Bitwise shifting (D) Bitwise complement Ans:B
Q.20 The C language includes the header file standard input & output in (A) stdlib.h library (B) stdio.h library (C) conio.h library (D) #include library Ans:B
Q.21 The value that follows the keyword CASE may only be (A) constants (B) variable (C) number (D) semicolon Ans:A
Q.22 The statement which is used to terminate the control from the loop is (A) break (B) continue (C) goto (D) exit Ans:A
Q.23 The machine registers are sometimes called (A) local variables (B) global variables (C) accumulators (D) static variables Ans:A
Q.24 Set of values of the same type, which have a single name followed by an index is called (A) function (B) structure (C) array (D) union Ans:C
Q.25 An array of pointers is same as (A) pointer to array (B) pointers to pointers (C) pointer to function (D) pointer to structure Ans:B
Q.26 What is the output of the following program segment? main() { long i = 65536; printf(%d\n, i); } (A) 0 (B) 65536 (C) -1 (D) 65 Ans:A
Q.27 What is the output of the following program segment? main() { int i = 1; do { printf(%d.., i); } while(i--); } (A) 0..1.. (B) 1..0.. (C) 0 (D) -1 Ans:B
Q.28 What is the output of the following program segment? main() { int i = ++2; printf(%d\n, i); } (A) 3 (B) 2 (C) 0 (D) -1 Ans:A It is a compilation error. However if we write i=2; ++i; then value of i is printed as 3.
Q.29 The name of all functions end with a (A) pair of parenthesis (B) semicolon (C) braces (D) colon Ans:A
Q.30 A float variable can store any variable within the range of (A) 7.1 10 38 to 7.1 10 38 (B) 4.3 10 38 to 4.3 1038 (C) 2.7 10 38 to 2.7 10 38 D) 2.1 10 38 to 2.1 10 38
Ans:B
Q.31 scanf() can be used for reading (A) double character (B) single character (C) multiple characters (D) no character Ans:C
Q.32 C allows a three-way transfer of control with the help of (A) unary operator (B) relational operator (C) ternary operator (D) comparison operator Ans:C
Q.33 The statement that transfers control to the beginning of the loop is called (A) break statement (B) exit statement (C) continue statement (D) goto statement Ans:C
Q.34 A variable which is visible only in the function in which it is defined, is called (A) static variable (B) auto variable (C) external variable (D) local variable Ans:D
Q.35 The number of arguments supplied from the command line, by convention, is known as (A) arg c (B) arg v (C) #define (D) #include Ans:A
Q.36 Output of the program given below is int i; main() { printf(%d, i); } (A) 1 (B) 0 (C) -1 (D) Null Ans:B
Q.37 What will be the output of the following program? main() { char *p = ayqm; printf (%c, ++*(p++));} (A) b (B) z (C) q (D) n Ans:A
Q.38 What will be the output of the following program? main() { int i = 5; printf(%d, i=++i==6); } (A) 0 (B) 1 (C) 7 (D) 6 Ans:B
Q.39 Determine which of the following is a valid character constant (A) \\ (B) \0 (C) xyz (D) \052 Ans:A
Q.40 The maximum value that an integer constant can have is (A) .32767 (B) 32767 (C) 1.7014e+38 (D) 1.7014e+38 Ans:B
Q.42 What will be the output of following program? main() { int x=15; printf(\n%d%d%d, x!=15, x=20, x<30); } (A) 0, 20, 1 (B) 15, 20, 30 (C) 0, 0, 0 (D) Error Ans:A
Q.43 How many times the following program would print (abc)? main() { printf(\nabc); main(); } (A) Infinite number of times (B) 32767 times (C) 65535 times (D) Till the stack does not overflow Ans:A
Q.44 What would be output of the following program? # define SQR(X) (X*X) main() { int a, b=3; a = SQR(b+2); printf(\n%d, a); } (A) 25 (B) 11 (C) Error (D) Garbage value Ans:B
Q.45 What would be output of the following program? #include "stdio.h" main() { printf(%d%d, size of (NULL!), size of ( )); } (A) 2 1 (B) 1 2 (C) 2 2 (D) 1 1 Ans:C
Q.46 What would be output of the following program, if the array begins at 65486? main() { int arr[ ] = {12, 14, 15, 23, 45}; printf(%u%u, arr+1, &arr+1); } (A) 65486, 65486 (B) 65488, 65488 (C) 65488, 65496 (D) None of the above Ans:C Array begins at address 65486 so arr+1=65488 as size of int is 2 bytes and &arr+1=65486+10=65496 as there are 5 elements in array.
Q.47 Given the statement, maruti.engine.bolts=25; which of the following is true? (A) Structure bolts is nested within structure engine (B) Structure engine is nested within structure maruti (C) Structure maruti is nested within structure engine (D) Structure maruti nested within structure bolts Ans:B
Q.48 Which amongst the following is not a keyword? (A) external (B) int (C) float (D) double Ans:A
Q.49 If a = 5 and b = 7 then the statement p = (a > b) : a ? b (A) assigns a value 5 to p (B) assigns a value 7 to p (C) assigns a value 8 to p (D) gives an error message Ans:D
Q.50 The expression P >> 6 shifts all bits of P six places to right. What is the value of P >> 6 if P = 0 6db7 ? (A) 01234 (B) 0001 0 (C) 0000 0 (D) 6 01B Ans:D
Q.51 If an integer occupies 4 bytes and a character occupies 1 bytes of memory, each element of the following structure would occupy how many bytes? struct name { int age; char name [20]; } (A) 5 (B) 24 (C) 21 (D) 22 Ans:B
Q.52 If an array is used as function argument, the array is passed (A) by value. (B) by reference (C) by name. (D) the array cannot be used as a function argument. Ans:B
Q.53 To access a structure element using a pointer, ___________ operator is used (A) dot (.) (B) pointer (&) (C) pointer (*) (D) arrow () Ans:D
Q.54 The library function sqrt( ) operates on a double precision argument. If, i is an integer variable, which one of the following calls would correctly compute sqrt(i)? (A) sqrt((double)i) (B) (double) sqrt(i) (C) (double) (sqrt(i)) (D) sqrt(i) Ans:A
Q.55 What will happen if the following loop is executed? int num = 0; do { --num; printf(%d, num); num++; }while (num >= 0); } (A) The loop will run infinite number of times. (B) The program will not enter the loop. (C) There will be a compilation error. (D) There will be runtime error. Ans:C
Q.56 The break statement causes an exit (A) Only from the innermost loop. (B) Only from the innermost switch. (C) From the innermost loop or switch. (D) From the program. Ans:C
Q.57 It is necessary to declare the type of function in the calling program if (A) Function returns an integer. (B) Function returns a non-integer value. (C) Function is not defined in the same file. (D) Function is called number of times. Ans:B
Q.58 The function fprintf is used in a program (A) When too many printf calls have been already used in the program. (B) In place of printf, since printf uses more memory. (C) When the output is to be printed on to a file. (D) When the type of variables to be printed are not known before. Ans:C
Q.59 The following statement displays float x = 2000.53; printf (%e, x);
Q.60 The output of the following is int a = 75; printf (%d%%, a); (A) 75 (B) 75%% (C) 75% (D) None of the above Ans:D
Q.61 The given FOR loop is for ( ; ; ) { printf( ); } (A) valid (B) indefinite (C) invalid (D) displays runtime errors Ans:D
Q.62 The following code displays main( ) { int *p; p = (int*) malloc(sizeof(int)); *p = 10; printf(p = %d\n, *p); }
(A) 10 (B) 1542 (address of p) (C) 20 (D) None of the above Ans:A
Q.63 The _______ operator is a technique to forcefully convert one data type to the others (A) Cast (B) Conversion (C) Type (D) Uniary Ans:A
Q.64 The output of the following will be for (x=1, y=5; x+y<=10; x++) { printf(%d%d, x,y); y++; } (A) 1 5 (B) 1 5 2 6 2 6 3 7 3 7 4 8 (C) 1 5 (D) 1 5 1 6 2 5 1 7 3 5 1 8 4 5 1 9 5 5 Ans:A
Q.65 The __________ statement causes immediate exit from the loop overriding the condition test
(A) Exit (B) Break (C) Goto (D) None of the above Ans:B
Q.66 The output of the following code is a = 5; a << 1; printf(%d, a); (A) 5 (B) 6 (C) 2 (D) 3 Ans:A
Q.67 The purpose for mode w+b in file operation is (A) create a binary file for write (B) create a binary file for read/write (C) open a binary file for writing (D) open a binary file for reading/writing Ans:B
Q.68 The operators << and >> are (A) assignment operator (B) relational operator (C) logical operator (D) bitwise shift operator Ans D
Q.69 Which of the following numerical value is invalid constant (A) .75 (B) 9.3e2 (C) 27,512 (D) 123456 Ans C
Q.70 A C program contains the following declaration int i=8, j=5 what would be the value of following expression? abs(i-2*j) (A) 2 (B) 4 (C) 6 (D) 8 Ans A
Q.71 What will be the output of the following program main( ) { int k, num=30; k=(num>5 ? (num<= 10 ? 100:200):500); printf(\n%d, num); } (A) 100 (B) 5 (C) 30 (D) 500 Ans C
Q.72 What is the output of the following code int n = 0, m=1; do { printf(%d, m); m++; } while(m<=n); (A) 0 (B) 2 (C) 1 (D) 4 Ans C
Q.73 If a=8 and b=15 then the statement x= (a>b) ? a:b; (A) assigns a value 8 to x (B) gives an error message (C) assigns a value 15 to x (D) assigns a value 7 to x Ans C
Q.74 What is the output of the following code int n=0, m; for (m=1; m<=n+1; m++) printf(%d, m); (A) 2 (B) 1 (C) 0 (D) 6 Ans B
Q.75 How many times the following loop be executed {
ch = b; while(ch >= a && ch <= z) ch++; } (A) 0 (B) 25 (C) 26 (D) 1 Ans B
Q.76 Which of the following is FALSE in C (A) Keywords can be used as variable names (B) Variable names can contain a digit (C) Variable names do not contain a blank space (D) Capital letters can be used in variable names Ans A
Q.77 int **ptr; is (A) Invalid declaration (B) Pointer to pointer (C) Pointer to integer (D) none of the above Ans B