C Questions
C Questions
C Questions
A ) They can contain alphanumeric characters as well as special characters B ) It is not an error to
declare a variable to be one of the keywords(like goto, static) C ) Variable names cannot start with a
digit D ) Variable can be of any length
3. 2. What is the output of this C code? #include <stdio.h> int main() { printf(“Hello World! %d \n”, x);
return 0; }
A ) Hello World! x; B ) Hello World! followed by a junk value C ) Compile time error D ) Hello
World!
4. Consider on following declaration: (i) short i=10; (ii) static i=10; (iii) unsigned i=10; (iv)
const i=10;
A ) Only (iv) is incorrect B ) Only (ii) and (iv) are incorrect C ) Only (ii),(iii) and (iv) are correct D )
All are correct declaration
5. What will happen if the below program is executed? #include <stdio.h> int main() { int main = 3;
printf(“%d”, main); return 0; }
A ) It will cause a compile-time error B ) It will cause a run-time error C ) It will run without any
error and prints 3 D ) It will experience infinite looping
A ) int my_num = 100,000; B ) int my_num = 100000; C ) int my num = 1000; D ) int $my_num
= 10000;
9. Which data type is most suitable for storing a number 65000 in a 32-bit system?
10. The format identifier ‘%i’ is also used for _____ data type?
12. Comment on the output of this C code? #include <stdio.h> int main() { float f1 = 0.1; if (f1 == 0.1)
printf(“equal\n”); else printf(“not equal\n”); }
1 points
14. What is the output of this C code? #include <stdio.h> int main() { char chr; chr = 128; printf(“%d\n”,
chr); return 0; }
15. What is the output of this C code? #include <stdio.h> int main() { int y = 10000; int y = 34;
printf(“Hello World! %d\n”, y); return 0; }
A ) Compile time error B ) Hello World! 34 C ) Hello World! 1000 D ) Hello World! followed by a
junk value
A ) char > int > float B ) int > char > float C ) char < int < double D ) double > char > int
19. What is the output of this C code? #include <stdio.h> int main() { float x = ‘a’; printf(“%f”, x); return 0;
}
A ) typedef int Boolean; B ) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays; C ) struct {char
name[10], int age}; D ) all of the mentioned
SET B
1. Which of the following function is more appropriate for reading in a multi-word string?
2. What will the SWAP macro in the following program be expanded to on preprocessing? will the code
compile? #include<stdio.h> #define SWAP(a, b, c)(c t; t=a, a=b, b=t) int main() { int x=10, y=20; SWAP(x,
y, int); printf(“%d %d\n”, x, y); return 0; }
A ) It compiles B ) Compiles with an warning C ) Not compile D ) Compiles and print nothing
3. In the following code what is ‘P’? typedef char *charp; const charp P;
4. Which library function used to find the last occurrence of a character in a string ?
6. In which stage the following code #include<stdio.h> gets replaced by the contents of the file stdio.h
A ) -1 B ) 1 C ) 0 D ) Yes
8. Which loop is most suitable to first perform the operation and then test the condition?
9. What is the output of this C code? #include <stdio.h> void main() { int i = 2; do { printf(“Hi”); } while (i
< 2) }
10. In C, if you pass an array as an argument to a function, what actually gets passed?
A ) Value of elements in array B ) First element of the array C ) Base address of the array D )
Address of the last element of array
11. In the following code, the P2 is Integer Pointer or Integer? typedef int *ptr; ptr p1, p2;
A ) The element will be set to 0. B ) The compiler would report an error. C ) The program may
crash if some important data gets overwritten. D ) The array size would appropriately grow.
13. What is the output of this C code? #include <stdio.h> int main() { int i = 0; do { i++; printf(“In while
loop\n”); } while (i < 3); }
A ) In while loop In while loop In while loop B ) In while loop In while loop C ) Depends on the
compiler D ) Compile time error
14. Which keyword is used to transfer control from a function back to the calling function ?
15. What is the output of this C code? #include <stdio.h> int main() { int i = 0, j = 0; while (i < 5, j < 10) { i+
+; j++; } printf(“%d, %d\n”, i, j); }
16. What is the output of this C code? #include <stdio.h> int main() { for (int i = 0;i < 1; i++) printf(“In for
loop\n”); }
A ) Compile time error B ) In for loop C ) Depends on the standard compiler implements D ) Run
time error
17. What would be the size of the following union declaration? #include <stdio.h> union uTemp { double
a; int b[10]; char c; }u; (Assuming size of double = 8, size of int = 4, size of char = 1)
A ) 4 B ) 8 C ) 40 D ) 80
20. If a variable is a pointer to a structure, then which of the following operator is used to access data
members of the structure through the pointer variable?
A ) . B ) & C ) * D ) ->