C Questions
C Questions
C Questions
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
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
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?
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
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)
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
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
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
1. 24
2. 4
3. 12
4. 10
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.