1Which operator is used to retrieve the address of a variable in C?
A.*
B.&
C.->
D.%
Correct Answer: &
Explanation:The ampersand operator () is known as the address-of operator. It returns the memory address of the variable it precedes.
Incorrect! Try again.
2What is the output of the following code snippet? int x = 10; int *p = &x; printf("%d", *p);
A.Address of x
B.10
C.Garbage value
D.Compilation Error
Correct Answer: 10
Explanation:The operator * is the dereference operator. *p accesses the value stored at the address contained in p, which is the value of x (10).
Incorrect! Try again.
3Which of the following best describes a Wild Pointer?
A.A pointer pointing to NULL
B.A pointer that has been freed
C.A pointer that is declared but not initialized
D.A pointer to a void type
Correct Answer: A pointer that is declared but not initialized
Explanation:A wild pointer is a pointer that has not been initialized to anything (not even NULL). It points to an arbitrary (random) memory location.
Incorrect! Try again.
4A pointer that points to a memory location that has been deleted or freed is called a __.
A.Null Pointer
B.Void Pointer
C.Dangling Pointer
D.Wild Pointer
Correct Answer: Dangling Pointer
Explanation:A dangling pointer arises when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory.
Incorrect! Try again.
5What is the size of a pointer variable in a 64-bit architecture?
A.2 bytes
B.4 bytes
C.8 bytes
D.Depends on the data type it points to
Correct Answer: 8 bytes
Explanation:In a 64-bit architecture, memory addresses are 64 bits long. Therefore, a pointer (which stores an address) requires 8 bytes () regardless of the data type it points to.
Incorrect! Try again.
6Which of the following statements about void pointers is true?
A.They can be dereferenced directly.
B.Pointer arithmetic is allowed directly on void pointers in standard C.
C.They can point to any data type.
D.They are automatically initialized to NULL.
Correct Answer: They can point to any data type.
Explanation:A void pointer is a generic pointer that can hold the address of any data type. However, it cannot be dereferenced directly without typecasting.
Incorrect! Try again.
7If int *ptr contains address 1000 and sizeof(int) is 4 bytes, what is the value of ptr + 1?
A.1001
B.1004
C.1002
D.1010
Correct Answer: 1004
Explanation:Pointer arithmetic adds the size of the data type the pointer points to. .
Incorrect! Try again.
8Which of the following operations is ILLEGAL for pointers?
A.Subtracting two pointers of the same type
B.Adding an integer to a pointer
C.Adding two pointers
D.Comparing two pointers
Correct Answer: Adding two pointers
Explanation:You cannot add two pointers together (e.g., ptr1 + ptr2). This operation has no logical meaning in memory addressing. You can, however, subtract them to find the distance between them.
Incorrect! Try again.
9What does the expression *ptr++ do?
A.Increments the pointer, then returns the value at the new address
B.Increments the value being pointed to
C.Returns the current value pointed to, then increments the pointer
D.It is a syntax error
Correct Answer: Returns the current value pointed to, then increments the pointer
Explanation:Due to operator precedence and associativity, *ptr++ is treated as *(ptr++). It returns the value at the current address, and then the pointer itself is incremented to the next memory location.
Incorrect! Try again.
10Consider int arr[5] = {1, 2, 3, 4, 5}; int *p = arr;. What is the value of *(p + 3)?
A.2
B.3
C.4
D.5
Correct Answer: 4
Explanation:p points to arr[0]. p + 3 points to arr[3]. Dereferencing it yields the value at index 3, which is 4.
Incorrect! Try again.
11How do you declare a pointer to a constant integer?
A.int const *ptr;
B.const int *ptr;
C.int * const ptr;
D.Both A and B
Correct Answer: Both A and B
Explanation:const int *ptr and int const *ptr both define a pointer to a constant integer. The value pointed to cannot be changed, but the pointer itself can change.
Incorrect! Try again.
12Which header file is required for dynamic memory management functions like malloc and calloc?
A.<stdio.h>
B.<stdlib.h>
C.<memory.h>
D.<string.h>
Correct Answer: <stdlib.h>
Explanation:The functions malloc, calloc, realloc, and free are defined in the standard library header <stdlib.h>.
Incorrect! Try again.
13What is the return type of malloc()?
A.int *
B.char *
C.void *
D.null
Correct Answer: void *
Explanation:malloc returns a generic void * pointer, which can be cast to any other pointer type. If allocation fails, it returns NULL.
Incorrect! Try again.
14Which function is used to allocate memory and initialize all bytes to zero?
A.malloc()
B.calloc()
C.realloc()
D.alloc()
Correct Answer: calloc()
Explanation:calloc() (contiguous allocation) allocates memory for an array of elements and initializes all bytes in the allocated storage to zero.
Incorrect! Try again.
15What is the correct syntax to allocate an array of 10 integers using malloc?
A.int ptr = (int )malloc(10);
B.int ptr = (int )malloc(10 * sizeof(int));
C.int ptr = malloc(10 int);
D.int ptr = (int )calloc(10 * sizeof(int));
Correct Answer: int ptr = (int )malloc(10 * sizeof(int));
Explanation:malloc takes the total number of bytes as an argument. To store 10 integers, you need bytes.
Incorrect! Try again.
16What is the purpose of the free() function?
A.To clear the values in memory
B.To release dynamically allocated memory back to the heap
C.To delete a pointer variable
D.To resize memory
Correct Answer: To release dynamically allocated memory back to the heap
Explanation:free() is used to deallocate memory that was previously allocated using malloc, calloc, or realloc, preventing memory leaks.
Incorrect! Try again.
17If realloc() fails to resize the memory, what happens to the original block?
A.It is freed automatically
B.It remains unchanged
C.It becomes a wild pointer
D.The program crashes immediately
Correct Answer: It remains unchanged
Explanation:If realloc fails, it returns NULL, but the original memory block remains valid and unchanged.
Incorrect! Try again.
18Which specific character is used to terminate a string in C?
A.'.'
B.'\0'
C.'\n'
D.'0'
Correct Answer: '\0'
Explanation:In C, strings are arrays of characters terminated by the null character \0 (ASCII value 0).
Incorrect! Try again.
19What is the output of sizeof("Hello") vs strlen("Hello")?
A.5 and 5
B.6 and 5
C.6 and 6
D.5 and 6
Correct Answer: 6 and 5
Explanation:sizeof includes the null terminator (). strlen counts only the visible characters (5).
Incorrect! Try again.
20Which function is safer than gets() for reading a string from the user?
A.scanf()
B.getch()
C.fgets()
D.getchar()
Correct Answer: fgets()
Explanation:gets() does not check for buffer overflow. fgets() allows you to specify the maximum size of the buffer, making it safer.
Incorrect! Try again.
21What does the function strcmp(str1, str2) return if str1 is lexicographically greater than str2?
A.
B.A negative integer
C.A positive integer
D.NULL
Correct Answer: A positive integer
Explanation:strcmp returns a positive integer (often the difference in ASCII values) if the first non-matching character in str1 is greater than that in str2.
Incorrect! Try again.
22Which library function is used to copy one string to another?
A.strcopy()
B.strcpy()
C.strncpy()
D.memcpy()
Correct Answer: strcpy()
Explanation:strcpy(dest, src) copies the string pointed to by src to dest.
Incorrect! Try again.
23What is the result of 'c' - 'a' in C?
A.Error
B.2
C.99
D.Variable
Correct Answer: 2
Explanation:Characters are stored as ASCII integers. The ASCII value of 'c' is 99 and 'a' is 97. .
Incorrect! Try again.
24Consider char *str = "Programming";. What is *(str + 3)?
A.'P'
B.'r'
C.'o'
D.'g'
Correct Answer: 'g'
Explanation:Index starts at 0. 'P'(0), 'r'(1), 'o'(2), 'g'(3).
Incorrect! Try again.
25What happens if you define char str[] = "Hello"; and then try str++?
A.Pointer moves to 'e'
B.Pointer moves to 'l'
C.Compilation Error
D.Undefined Behavior
Correct Answer: Compilation Error
Explanation:An array name is a constant pointer. You cannot increment a constant pointer (e.g., str++ is illegal), though you could do ptr = str; ptr++;.
Incorrect! Try again.
26Which function appends one string to the end of another?
A.stradd()
B.strcat()
C.strappend()
D.strncat()
Correct Answer: strcat()
Explanation:strcat(dest, src) concatenates src to the end of dest.
Incorrect! Try again.
27When passing a one-dimensional array to a function, what is actually passed?
A.The value of the first element
B.The value of all elements
C.The address of the first element
D.The address of the last element
Correct Answer: The address of the first element
Explanation:Arrays decay to pointers when passed to functions. The address of the 0th index is passed.
Incorrect! Try again.
28Which of the following creates a "Memory Leak"?
A.Allocating memory and forgetting to free it
B.Accessing memory after freeing it
C.Using uninitialized pointers
D.Allocating 0 bytes
Correct Answer: Allocating memory and forgetting to free it
Explanation:A memory leak occurs when dynamically allocated memory is not deallocated (freed), causing the available memory to reduce over time.
Incorrect! Try again.
29What is the difference between calloc and malloc arguments?
A.malloc takes two args, calloc takes one
B.malloc takes one arg, calloc takes two
C.Both take one arg
D.Both take two args
Correct Answer: malloc takes one arg, calloc takes two
Explanation:malloc(size_t size) takes total bytes. calloc(size_t num, size_t size) takes the number of elements and the size of each element.
Incorrect! Try again.
30If int a = 5; int *p = &a;, which expression effectively doubles the value of a?
A.p = p * 2;
B.p = p * 2;
C.&a = &a * 2;
D.a = &p * 2;
Correct Answer: p = p * 2;
Explanation:*p accesses the value of a. *p * 2 calculates 10, and assigning it back updates a.
Incorrect! Try again.
31What does strrev() do?
A.Reverses a string
B.Repeats a string
C.Reserves memory for string
D.Returns string revision
Correct Answer: Reverses a string
Explanation:strrev() is a non-standard function (often found in older compilers like Turbo C) that reverses a given string in place.
Incorrect! Try again.
32Which format specifier is used to print a memory address (pointer) in printf?
A.%d
B.%u
C.%x
D.%p
Correct Answer: %p
Explanation:%p is the standard format specifier for printing pointer addresses (usually in hexadecimal).
Incorrect! Try again.
33Given char *s = "Hello"; s[0] = 'M';. What happens?
Explanation:String literals like "Hello" are often stored in read-only memory segments. Attempting to modify them via a pointer results in undefined behavior (often a segmentation fault).
Incorrect! Try again.
34How do you calculate the length of a string without using library functions?
A.Use sizeof
B.Loop until \n is found
C.Loop until \0 is found
D.Subtract start address from end address
Correct Answer: Loop until \0 is found
Explanation:You iterate through the character array incrementing a counter until the character at the current index is the null terminator \0.
Incorrect! Try again.
35Which standard function converts a string representation of a number to an integer (e.g., "123" to 123)?
A.stroint()
B.atoi()
C.itoa()
D.to_int()
Correct Answer: atoi()
Explanation:atoi() (ASCII to Integer) converts a string to an integer type. It is found in <stdlib.h>.
Incorrect! Try again.
36What is the equivalent pointer expression for arr[i]?
A.*arr + i
B.*(arr + i)
C.&arr + i
D.arr + i
Correct Answer: *(arr + i)
Explanation:In C, array subscript notation arr[i] is defined to be equivalent to *(arr + i).
Incorrect! Try again.
37If ptr is a null pointer, what does free(ptr) do?
A.Causes a runtime error
B.Does nothing
C.Crashes the system
D.Prints an error message
Correct Answer: Does nothing
Explanation:The standard states that if the argument passed to free() is a NULL pointer, no operation is performed.
Incorrect! Try again.
38Which is the correct way to declare a pointer to a function taking two integers and returning void?
A.void *func(int, int);
B.void (*func)(int, int);
C.void *func(int, int);
D.void *(func)(int, int);
Correct Answer: void (*func)(int, int);
Explanation:The parenthesis around *func are necessary to indicate it is a pointer to a function, rather than a function returning a void pointer.
Incorrect! Try again.
39What is the value of NULL typically defined as in C?
A.-1
B.1
C.0 or (void *)0
D.Infinite
Correct Answer: 0 or (void *)0
Explanation:NULL is a macro usually defined as integer constant 0 or (void *)0 in <stddef.h> or <stdio.h>.
Incorrect! Try again.
40In the expression char str[20];, str acts as a:
A.Constant pointer
B.Variable pointer
C.Void pointer
D.Null pointer
Correct Answer: Constant pointer
Explanation:The name of an array acts as a constant pointer to the first element of the array. Its address cannot be changed.
Incorrect! Try again.
41What is the output of printf("%d", sizeof(char *)); on a 32-bit machine?
A.1
B.2
C.4
D.8
Correct Answer: 4
Explanation:On a 32-bit system, memory addresses are 32 bits (4 bytes). All pointers, regardless of type (char*, int*, etc.), are the same size.
Incorrect! Try again.
42Which function allows searching for a character within a string?
A.strstr()
B.strchr()
C.strcat()
D.strtok()
Correct Answer: strchr()
Explanation:strchr() locates the first occurrence of a specific character in a string.
Incorrect! Try again.
43What is the correct logic to swap two numbers using pointers pa and pb?
A.temp = pa; pa = pb; pb = temp;
B.temp = pa; pa = pb; pb = temp;
C.pa = pb;
D.pa = *pb;
Correct Answer: temp = pa; pa = pb; pb = temp;
Explanation:To swap values, you must dereference the pointers (*pa, *pb) to access and modify the actual data.
Incorrect! Try again.
44If int arr[] = {10, 20}; int *p = arr;, what is the result of ++*p?
A.p points to 20
B.Value at arr[0] becomes 11
C.Value at arr[0] becomes 20
D.Syntax error
Correct Answer: Value at arr[0] becomes 11
Explanation:Precedence of ++ (prefix) and * is right-to-left. However, ++*p is interpreted as ++(*p). We increment the value pointed to by p. 10 becomes 11.
Incorrect! Try again.
45Which of the following creates a 2D array dynamically (rows=R, cols=C)?
A.malloc(R C sizeof(int))
B.malloc(R) then malloc(C) loop
C.An array of pointers where each points to an allocated integer array
D.All of the above
Correct Answer: An array of pointers where each points to an allocated integer array
Explanation:The standard way to create a dynamic 2D array (pointer to pointer) is to allocate an array of pointers (rows), and then for each row pointer, allocate an array of integers (cols).
Incorrect! Try again.
46What happens if strcat is used without ensuring the destination string has enough space?
A.Automatic resizing
B.Buffer Overflow
C.Truncation of string
D.Null pointer exception
Correct Answer: Buffer Overflow
Explanation:strcat does not check size. If the destination array is too small, it overwrites adjacent memory, causing a buffer overflow.
Incorrect! Try again.
47To read a string with spaces (e.g., "New York"), which conversion specifier should be used in scanf?
A.%s
B.%[^
]
C.%c
D.%string
Correct Answer: %[^
]
Explanation:%s stops reading at the first whitespace. %[^ ] (scanset) reads until a newline character is encountered, effectively reading the whole line.
Incorrect! Try again.
48Which pointer type is returned by pointer subtraction?
A.int *
B.ptrdiff_t
C.void *
D.size_t
Correct Answer: ptrdiff_t
Explanation:Subtracting two pointers returns a signed integer result of type ptrdiff_t (defined in <stddef.h>), representing the number of elements between them.
Incorrect! Try again.
49What is the purpose of tolower() function in character arithmetic?
A.Converts string to lowercase
B.Converts a single character to lowercase
C.Checks if character is lower case
D.Lowers the memory address
Correct Answer: Converts a single character to lowercase
Explanation:tolower() (from <ctype.h>) takes a character argument and returns its lowercase equivalent if it is an uppercase letter.
Incorrect! Try again.
50Given char s[] = "World";, what is the valid way to assign a new string?
A.s = "Hello";
B.strcpy(s, "Hello");
C.s[] = "Hello";
D.s.value = "Hello";
Correct Answer: strcpy(s, "Hello");
Explanation:Arrays cannot be assigned directly using = after declaration. You must use strcpy to copy the content into the array.
Incorrect! Try again.
Give Feedback
Help us improve by sharing your thoughts or reporting issues.