Blank
Blank
Blank
A) `int 4num;`
B) `int num4;`
C) `int num-4;`
D) `int num 4;`
12. Which of the following is true about the scope of a variable declared inside a function in C?
A) It is global and can be accessed from anywhere in the program.
B) It is local to the function and cannot be accessed outside.
C) It is local to the le and can be accessed by other functions in the same le.
D) It is local to the block of code in which it is declared.
14. Which of the following statements is correct about the `malloc` function?
A) `malloc` allocates memory and initializes it to zero.
B) `malloc` allocates memory but does not initialize it.
C) `malloc` allocates memory and initializes it to a speci c value provided by the user.
D) `malloc` does not allocate memory but only initializes it.
19. Which of the following C statements is used to correctly read a string input from the user?
A) `scanf("%s", str);`
B) `scanf("%[^\n]s", str);`
C) `scanf("%c", str);`
D) `gets(str);`
30. How do you allocate memory for an array of 10 integers using malloc?
A) `int *arr = malloc(10);`
B) `int *arr = malloc(10 * sizeof(int));`
C) `int arr[10];`
D) `int arr = malloc(10 * sizeof(int));`
33. Which of the following operators is used to access the value at the address stored in a pointer
variable?
A) &
B) *
C) ->
D) .
35. Which function is used to read a string from the standard input in C?
fi
fi
A) gets()
B) scanf()
C) fgets()
D) read()
36. How do you declare a pointer to a function that returns an int and takes a oat as an
argument?
A) `int (*ptr)( oat);`
B) `int *ptr( oat);`
C) `int ptr( oat);`
D) `int (*ptr) oat;`
44. Which of the following function is used to write a character to the console in C?
A) write()
B) putchar()
C) puts()
D) printf()
55. What is the maximum number of characters that can be held in the string variable char
address line[40]?
A) 39
B) 41
C) 40
D) 38
56. Which of the following STL template class is a container adaptor class?
A) Deque
B) Vector
C) List
D) Stack
57. If addition had higher precedence than multiplication, then the value of the expression (1 + 2 *
3 + 4 * 5) would be which of the following?
A) 27
B) 105
C) 69
D) 47
62. Which of the following will occur if we call the free() function on a NULL pointer?
A) The program will execute normally
B) Compilation Error
C) Runtime error
D) Unde ned behavior
63. Which of the following should be used to free memory from a pointer allocated using the
"new" operator?
fi
fi
ff
fi
A) free()
B) realloc()
C) delete
D) None of the above
66. How is the 3rd element in an array accessed based on pointer notation?
A) *a + 3
B) *(*a+3)
C) *(a + 3)
D) & (a+3)
73. What is the 16-bit compiler allowable range for integer constants?
fi
fi
A) -3.4e38 to 3.4e38
B) -32767 to 32768
C) -32668 to 32667
D) -32768 to 32767
75. If p is an integer pointer with a value 1000, then what will the value of p + 5 be?
A) 1005
B) 1020
C) 1004
D) 1010
77. What is the size of the int data type (in bytes) in C?
A) 4
B) 8
C) 2
D) 1
83. Assume that objects of the type short, oat and long occupy 2 bytes, 4 bytes and 8 bytes,
respectively. The memory requirement for variable t, ignoring alignment
```c
struct {
short s [5];
union {
oat y;
long z;
}u;
} t;
```
A) 22 bytes
B) 18 bytes
C) 14 bytes
D) 10 bytes
99. Consider the following C code. Assume that unsigned long int type length is 64 bits.
```c
unsigned long int fun(unsigned long int n){
unsigned long int i, j = 0, sum = 0;
for (i = n; i > 1; i = i/2) j++;
for ( ; j > 1; j = j/2) sum++;
return(sum);
}
```
The value returned when we call fun with the input 240 is
A) 4
B) 5
C) 6
D) 40