You are on page 1of 8

C Programming MCQ Questions

1. What is the disadvantage of arrays in C?


1. Multiple other data structures can be implemented using arrays
2. the amount of memory to be allocated needs to be known beforehand.
3. Elements of array can be accessed in constant time
4. Elements are stored in contiguous memory blocks

2. Directives are translated by the__________


1. Pre-processor
2. Compiler
3. Linker
4. Editor

3. What is the maximum number of characters that can be held in the string variable
char address line [40]?
1. 39
2. 41
3. 40
4. 38

4. Which of the following SLT template class is a container adaptor class?


1. Dequeue
2. Vector
3. List
4. Stack

5. If addition had higher precedence than multiplication, then the value of the
expression (1 + 2 * 3 + 4 * 5) would be which of the following?
1. 27
2. 105
3. 69
4. 47
6. What is the return type of the fopen() function in C?

1. An integer
2. pointer to a FILE object
3. Pointer to an integer
4. None of the above

7. Which of the following is not a storage class specifier in C?

1. extern
2. volatile
3. typedef
4. static

8. Which of the following will occur if we call the free() function on a NULL pointer?

1. The program will execute normally


2. Compilation Error
3. Runtime error
4. undefined behavior

9. Which of the following should be used to free memory from a pointer allocated
using the “new” operator?

1. free()
2. realloc()
3. delete
4. None of the above

10. Which data structure is used to handle recursion in C?

1. Stack
2. Queue
3. Trees
4. Dequeue
11. Which of the following is not true about structs in C?
1. Functions are allowed inside structs
2. Constructors are not allowed inside structs
3. No data hiding
4. Cannot have static members in struct body

12. How is the 3rd element in an array accessed based on pointer notation?

1. *a + 3
2. *(*a+3)
3. *(a + 3)
4. & (a+3)

13. What is required in each C program?

1. The program does not require any function.


2. The program must have at least one function
3. Output data
4. Input data

14. Why is a macro used in place of a function?

1. It reduces code size


2. It reduces execution time
3. It increases code size
4. It increases execution time

15. If p is an integer pointer with a value 1000, then what will the value of p + 5 be?

1. 1005
2. 1020
3. 1004
4. 1010

16. Which of the following declaration is not supported by C language?

1. String str;
2. char *str;
3. float str = 3e2;
4. Both “String str;” and “float str = 3e2;”

17. Property which allows to produce different executable for different platforms in C
is called?

1. File inclusion
2. Selective inclusion
3. Conditional compilation
4. Recursive macros

18. What will happen if the following C code is executed?


#include <stdio.h>
int main()
{
int main = 3;
printf("%d", main);
return 0;
}
1. It will cause a compile-time error
2. It will cause a run-time error
3. It will run without any error and prints 3
4. It will experience infinite looping

19. What will be the output of the following C code?


#include <stdio.h>
enum birds {SPARROW, PEACOCK, PARROT};
enum animals {TIGER = 8, LION, RABBIT, ZEBRA};
int main()
{
enum birds m = TIGER;
int k;
k = m;
printf("%d\n", k);
return 0;
}
1. 0
2. Compile time error
3. 1
4. 8

20. What is an example of iteration in C?


1. for
2. while
3. do-while
4. All of the mentioned

21. What will be the output of the following C code if the input entered as first and
second number is 5 and 6 respectively?
#include<stdio.h>
#include<stdlib.h>
main()
{
int *p;
p=(int*)calloc(3*sizeof(int));
printf("Enter first number\n");
scanf("%d",p);
printf("Enter second number\n");
scanf("%d",p+2);
printf("%d%d",*p,*(p+2));
free(p);
}
1. 56
2. Address of the locations where the two numbers are stored
3. 57
4. Error

22. The Following Code is an Example of__________


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
char *p,*q;
p=(char*)malloc(3*sizeof(char));
q=p;
strcpy(p,"hello");
printf("p=%s",p);
printf("q=%s",q);
free(q);
q=NULL;
gets(p);
gets(q);
printf("%s",p);
printf(“%s”,q);
}
1. Memory leak
2. Dangling pointer
3. Static memory allocation
4. Linked list

23. The purpose of the preprocessor directive #error is that ____________


1. It rectifies any error present in the code
2. It rectifies only the first error which occurs in the code
3. It causes the preprocessor to report a fatal error
4. It causes the preprocessor to ignore an error

24. What will be the output of the following C code?


#include<stdio.h>
main()
{
int n;
n=f1(4);
printf("%d",n);
}
f1(int x)
{
int b;
if(x==1)
return 1;
else
b=x*f1(x-1);
return b;
}

1. 24
2. 4
3. 12
4. 10

25. What will be the output of the following C code?


include <stdio.h>
int main() {
char arr[] = "Hello";
printf("%d", sizeof(arr) - 1);
return 0;
}
1. 5
2. 6
3. 4
4. Compiler Error

26. Which of the following are valid ways to terminate a C program? Select all that
apply
1. return 0;
2. exit(0);
3. end();
4. quit();
5. break;

27. What are the valid ways to comment code in C? Select all that apply
1. // Single-line comment
2. /* Multi-line comment */
3. # Single-line comment
4. ' Single-line comment
5. < ! - - Multi-line comment - - >

28. What are the valid ways to handle errors in C programming? Select all that apply
1. Using return codes to indicate errors.
2. Using the assert() macro.
3. Using exception handling mechanisms like try-catch.
4. Using error handling functions like perror().
5. Using preprocessor directives to handle errors.

29. Which of the following are valid methods to access command-line arguments in
C? Select all that apply
1. Using argc and argv parameters in the main() function.
2. Using the getopt() function.
3. Using environment variables.
4. Using the commandline_args array in the stdio.h library.
5. Using the scanf() function with appropriate format specifiers.

30. Which of the following are valid methods to access command-line arguments in
C? Select all that apply
1. Using argc and argv parameters in the main() function.
2. Using the getopt() function.
3. Using environment variables.
4. Using the commandline_args array in the stdio.h library.
5. Using the scanf() function with appropriate format specifiers.

You might also like