0% found this document useful (0 votes)
568 views4 pages

C Questions

The document contains 20 multiple choice questions about C programming concepts such as variable names, data types, operators, functions, pointers, arrays, structures and more. The questions cover fundamental and advanced C programming topics to test one's understanding of the C language.

Uploaded by

Goho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
568 views4 pages

C Questions

The document contains 20 multiple choice questions about C programming concepts such as variable names, data types, operators, functions, pointers, arrays, structures and more. The questions cover fundamental and advanced C programming topics to test one's understanding of the C language.

Uploaded by

Goho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Which of the following is true for variable names in C?

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

2. All keywords in C are in

A ) LowerCase letters B ) UpperCase letters C ) CamelCase letters D ) None

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

6. Which of the following is not a valid variable name declaration?

A ) float PI = 3.14; B ) double PI = 3.14; C ) int PI = 3.14; D ) #define PI 3.14;

7. Which is valid C expression?

A ) int my_num = 100,000; B ) int my_num = 100000; C ) int my num = 1000; D ) int $my_num
= 10000;

8. What is the size of an int data type?

A ) 4 Bytes B ) 8 Bytes C ) Depends on the system/compiler D ) Cannot be determined

9. Which data type is most suitable for storing a number 65000 in a 32-bit system?

A ) short B ) int C ) long D ) double

10. The format identifier ‘%i’ is also used for _____ data type?

A ) char B ) int C ) float D ) double


11. Variable name resolving (number of significant characters for uniqueness of variable) depends on

A ) Compiler and linker implementations B ) Assemblers and loaders implementations C ) C


language D ) None

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”); }

A ) equal B ) not equal C ) Output depends on compiler D ) None of the mentioned

1 points

13. Which of the following is not a valid C variable name?

A ) int variable_count B ) int number C ) float rate D ) int $main

14. What is the output of this C code? #include <stdio.h> int main() { char chr; chr = 128; printf(“%d\n”,
chr); return 0; }

A ) 128 B ) -128 C ) Depends on the compiler D ) None of the mentioned

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

16. Which of the following cannot be a variable name in C?

A ) Volatile B ) true C ) friend D ) export

17. Which is correct with respect to size of the datatypes?

A ) char > int > float B ) int > char > float C ) char < int < double D ) double > char > int

18. Literal means ?

A ) a string. B ) a string constant. C ) a character. D ) an alphabet.

19. What is the output of this C code? #include <stdio.h> int main() { float x = ‘a’; printf(“%f”, x); return 0;
}

A ) a B ) run time error C ) a.0000000 D ) 97.000000

20. Which of the following is a User-defined data type?

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?

A ) printf(); B ) scanf(); C ) gets(); D ) puts();

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;

A ) P is a constant B ) P is a character constant C ) P is character type D ) None of above

4. Which library function used to find the last occurrence of a character in a string ?

A ) strnstr() B ) laststr() C ) strrchr() D ) strstr()

5. How will you free the allocated memory ?

A ) remove(var-name); B ) free(var-name); C ) delete(var-name); D ) dalloc(var-name);

6. In which stage the following code #include<stdio.h> gets replaced by the contents of the file stdio.h

A ) During editing B ) During linking C ) During execution D ) During preprocessing

7. If the two strings are identical, then strcmp() function returns

A ) -1 B ) 1 C ) 0 D ) Yes

8. Which loop is most suitable to first perform the operation and then test the condition?

A ) for loop B ) while loop C ) do-while loop D ) None of the mentioned

9. What is the output of this C code? #include <stdio.h> void main() { int i = 2; do { printf(“Hi”); } while (i
< 2) }

A ) Compile time error B ) Hi Hi C ) Hi D ) No output

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 ) Integer B ) Integer pointer C ) Error in declaration D ) None of above


12. What will happen if in a C program you assign a value to an array element whose subscript exceeds
the size of array?

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 ?

A ) switch B ) goto C ) go back D ) return

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); }

A ) 5, 5 B ) 5, 10 C ) 10,10 D ) Syntax error

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

18. In which header file is the NULL macro defined?

A ) stdio.h B ) stddef.h C ) stdio.h and stddef.h D ) math.h

19. What does the following declaration mean? int (*ptr)[10];

A ) ptr is array of pointers to 10 integers B ) ptr is a pointer to an array of 10 integers C ) ptr is an


array of 10 integers D ) ptr is an pointer to array

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 ) ->

You might also like