1Which operator is used to return the memory address of a variable?
A.*
B.&
C.->
D.%
Correct Answer: &
Explanation:The address-of operator & is used to obtain the memory address of a variable.
Incorrect! Try again.
2What is the correct syntax to declare a pointer to an integer?
A.int ptr;
B.int *ptr;
C.int &ptr;
D.ptr int;
Correct Answer: int *ptr;
Explanation:To declare a pointer variable in C, we use the asterisk * before the pointer name. int *ptr; declares ptr as a pointer to an integer.
Incorrect! Try again.
3What 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:On a 64-bit architecture, memory addresses are 64 bits long, so a pointer typically occupies 8 bytes, regardless of the data type it points to.
Incorrect! Try again.
4What is the result of the expression *ptr if ptr is a pointer holding the address of variable x?
A.The address of x
B.The value of x
C.The address of ptr
D.The size of x
Correct Answer: The value of x
Explanation:The dereference operator * accesses the value stored at the address held by the pointer. If ptr points to x, *ptr gives the value of x.
Incorrect! Try again.
5What is a Null Pointer?
A.A pointer that points to a specific valid address.
B.A pointer that has not been initialized.
C.A pointer pointing to address 0 or explicitly assigned NULL.
D.A pointer pointing to a deleted variable.
Correct Answer: A pointer pointing to address 0 or explicitly assigned NULL.
Explanation:A Null Pointer is a pointer that is assigned a reserved value (usually 0 or the macro NULL) indicating that it does not point to any valid object.
Incorrect! Try again.
6Which of the following defines a Void Pointer?
A.A pointer that points to nothing.
B.A generic pointer that can point to any data type.
C.A pointer that returns a null value.
D.A pointer used for arithmetic operations.
Correct Answer: A generic pointer that can point to any data type.
Explanation:A void pointer (void *) is a generic pointer type that has no associated data type. It can hold the address of any type of variable but cannot be directly dereferenced without casting.
Incorrect! Try again.
7What happens if you try to dereference a void pointer without typecasting?
A.It returns 0.
B.It works normally.
C.It causes a compilation error.
D.It returns garbage value.
Correct Answer: It causes a compilation error.
Explanation:The compiler does not know the size or type of the data pointed to by a void *, so dereferencing it directly results in a compilation error.
Incorrect! Try again.
8A pointer that points to a memory location that has been deleted (freed) is called:
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 de-allocated, without modifying the value of the pointer, so the pointer still points to the memory location of the de-allocated memory.
Incorrect! Try again.
9What is a Wild Pointer?
A.A pointer pointing to NULL.
B.An uninitialized pointer.
C.A pointer pointing to a function.
D.A pointer stored in heap memory.
Correct Answer: An uninitialized pointer.
Explanation:Uninitialized pointers are known as wild pointers because they point to some arbitrary memory location and may cause a program to crash or behave unexpectedly.
Incorrect! Try again.
10If int *p points to address 1000 and sizeof(int) is 4 bytes, what is the value of p + 1?
A.1001
B.1004
C.1002
D.1010
Correct Answer: 1004
Explanation:Pointer arithmetic honors the data type size. Adding 1 to a pointer increments the address by sizeof(type). Here, .
Incorrect! Try again.
11Which of the following arithmetic operations is NOT allowed on pointers?
A.Adding an integer to a pointer
B.Subtracting an integer from a pointer
C.Subtracting two pointers of the same type
D.Adding two pointers
Correct Answer: Adding two pointers
Explanation:Adding two memory addresses together makes no logical sense in memory management and is forbidden in C.
Incorrect! Try again.
12What is the result of subtracting two pointers of the same type?
A.The sum of their addresses
B.The number of elements between the two pointers
C.The multiplication of addresses
D.A pointer to the middle element
Correct Answer: The number of elements between the two pointers
Explanation:Subtracting two pointers returns the number of elements (of the pointer's type) separating them, not the byte difference.
Incorrect! Try again.
13Consider the declaration int a[5] = {10, 20, 30, 40, 50};. What is *(a + 2) equal to?
A.10
B.20
C.30
D.Address of 30
Correct Answer: 30
Explanation:a acts as a pointer to the first element. a + 2 points to the third element (index 2). Dereferencing it *(a+2) gives the value at index 2, which is 30.
Incorrect! Try again.
14Which of the following is equivalent to arr[i]?
A.&arr + i
B.*(arr + i)
C.*arr + i
D.(arr + i)
Correct Answer: *(arr + i)
Explanation:In C, array subscripting is defined in terms of pointers. The expression arr[i] is exactly equivalent to *(arr + i).
Incorrect! Try again.
15What is the primary difference between an array name and a pointer variable?
A.Array name is a constant pointer; pointer variable is not.
B.Pointer variable cannot store address of array.
C.Array name cannot be dereferenced.
D.There is no difference.
Correct Answer: Array name is a constant pointer; pointer variable is not.
Explanation:An array name acts like a constant pointer (base address) and cannot be incremented or decremented (e.g., arr++ is illegal), whereas a pointer variable can be modified.
Incorrect! Try again.
16When passing a pointer to a function, what method of parameter passing is simulated?
A.Call by value
B.Call by reference
C.Call by name
D.Call by constant
Correct Answer: Call by reference
Explanation:Passing a pointer allows the function to modify the actual memory location of the variable in the caller, simulating Call by Reference.
Incorrect! Try again.
17Which library header must be included to use malloc, calloc, and free?
A.<stdio.h>
B.<string.h>
C.<stdlib.h>
D.<alloc.h>
Correct Answer: <stdlib.h>
Explanation:Dynamic memory management functions are defined in the <stdlib.h> standard library header.
Incorrect! Try again.
18What is the return type of the malloc function?
A.int *
B.char *
C.void *
D.null
Correct Answer: void *
Explanation:malloc returns a void * (generic pointer) to the allocated memory, which should typically be cast to the desired pointer type.
Incorrect! Try again.
19How does calloc differ from malloc regarding memory initialization?
A.malloc initializes memory to zero; calloc does not.
B.calloc initializes memory to zero; malloc contains garbage values.
Explanation:calloc allocates memory and clears it (sets to zero), whereas malloc allocates memory but leaves the content uninitialized (garbage values).
Incorrect! Try again.
20Which function is used to resize a previously allocated memory block?
A.malloc
B.calloc
C.realloc
D.memalloc
Correct Answer: realloc
Explanation:realloc (re-allocation) is used to change the size of the memory block pointed to by a pointer that was previously allocated.
Explanation:calloc takes two arguments: the number of elements to allocate and the size of each element in bytes.
Incorrect! Try again.
22What happens if you do not free dynamically allocated memory before the program terminates?
A.Compilation error
B.Memory Leak
C.Segmentation fault
D.Nothing, OS always frees it instantly
Correct Answer: Memory Leak
Explanation:Failure to free dynamically allocated memory results in a memory leak, where memory remains occupied and unusable until the OS reclaims it (usually at program termination, but bad practice for long-running apps).
Incorrect! Try again.
23What value do malloc and calloc return if the memory allocation fails?
A.-1
B.0
C.NULL
D.Garbage value
Correct Answer: NULL
Explanation:If the system cannot allocate the requested memory, these functions return a NULL pointer.
Incorrect! Try again.
24In C, strings are represented as:
A.A primitive data type 'string'
B.An array of characters terminated by a null character
C.An object of String class
D.A pointer to an integer
Correct Answer: An array of characters terminated by a null character
Explanation:C does not have a native string type. Strings are arrays of char terminated by the special character \0.
Incorrect! Try again.
25Which character serves as the string terminator in C?
A.'\n'
B.'\0'
C.'0'
D.'\t'
Correct Answer: '\0'
Explanation:The Null character \0 (ASCII value 0) marks the end of a string in C.
Incorrect! Try again.
26What is the output size of sizeof("Hello")?
A.5
B.6
C.4
D.8
Correct Answer: 6
Explanation:"Hello" has 5 characters plus the implicit null terminator \0. So, bytes.
Incorrect! Try again.
27Which function is unsafe to use for reading strings because it does not check buffer length?
A.scanf
B.fgets
C.gets
D.getchar
Correct Answer: gets
Explanation:gets() reads a line from stdin into a buffer without checking the size of the buffer, leading to potential buffer overflows. It is deprecated/removed in modern C.
Incorrect! Try again.
28What is the difference between char s[] = "Hello"; and char *p = "Hello";?
A.No difference.
B.s is modifiable, p points to a string literal which is likely read-only.
C.p is modifiable, s is read-only.
D.s allows pointer arithmetic, p does not.
Correct Answer: s is modifiable, p points to a string literal which is likely read-only.
Explanation:char s[] allocates memory on the stack and copies "Hello" into it (modifiable). char *p points to the string literal "Hello" stored in read-only memory section.
Incorrect! Try again.
29Which format specifier is used to read a string using scanf?
A.%c
B.%s
C.%d
D.%f
Correct Answer: %s
Explanation:%s is the format specifier for strings. It reads characters until whitespace is encountered.
Incorrect! Try again.
30Which library function calculates the length of a string?
A.strlength()
B.size()
C.strlen()
D.strcount()
Correct Answer: strlen()
Explanation:strlen() is the standard library function in <string.h> to calculate the length of a string (excluding the null terminator).
Incorrect! Try again.
31What does strcpy(dest, src) do?
A.Concatenates src to dest
B.Compares dest and src
C.Copies the content of src to dest
D.Returns the length of src
Correct Answer: Copies the content of src to dest
Explanation:strcpy copies the string pointed to by src (including the null terminator) to the buffer pointed to by dest.
Incorrect! Try again.
32Which header file is required for string manipulation functions like strcpy and strcmp?
A.<stdlib.h>
B.<string.h>
C.<stdio.h>
D.<conio.h>
Correct Answer: <string.h>
Explanation:The standard string manipulation functions are declared in <string.h>.
Incorrect! Try again.
33What does strcmp(s1, s2) return if s1 and s2 are identical?
A.1
B.-1
C.0
D.Non-zero
Correct Answer: 0
Explanation:strcmp returns 0 if both strings are lexicographically equal.
Incorrect! Try again.
34If strcat(s1, s2) is executed, what is the result?
A.s1 is appended to s2
B.s2 is appended to s1
C.s1 and s2 are copied to a new string
D.s1 is overwritten by s2
Correct Answer: s2 is appended to s1
Explanation:strcat concatenates (appends) the source string (s2) to the end of the destination string (s1).
Incorrect! Try again.
35What will strlen("Code") return?
A.4
B.5
C.3
D.Undefined
Correct Answer: 4
Explanation:strlen counts the number of characters before the null terminator. "Code" has 4 characters.
Incorrect! Try again.
36How do you correctly convert a character digit '5' to the integer 5?
A.'5' + 0
B.(int)'5'
C.'5' - '0'
D.atoi('5')
Correct Answer: '5' - '0'
Explanation:In ASCII, digits are sequential. Subtracting the character '0' from any digit character gives its integer equivalent (e.g., ).
Incorrect! Try again.
37What function is used to convert a string to a long integer?
A.atoi
B.atol
C.itoa
D.strtod
Correct Answer: atol
Explanation:atol stands for ASCII to Long. It converts a string representing a number to a long integer.
Incorrect! Try again.
38What logic converts an uppercase letter ch to lowercase?
A.ch - 32
B.ch + 32
C.ch * 2
D.ch / 2
Correct Answer: ch + 32
Explanation:In ASCII, uppercase letters start at 65 ('A') and lowercase at 97 ('a'). The difference is 32. To go from Upper to Lower, you add 32.
Incorrect! Try again.
39Which function searches for the first occurrence of a character in a string?
A.strchr()
B.strstr()
C.strrchr()
D.strtok()
Correct Answer: strchr()
Explanation:strchr() locates the first occurrence of a specific character in a string and returns a pointer to it.
Incorrect! Try again.
40What does strstr(haystack, needle) do?
A.Finds a character in a string
B.Concatenates two strings
C.Finds the first occurrence of substring 'needle' in 'haystack'
D.Compares two strings
Correct Answer: Finds the first occurrence of substring 'needle' in 'haystack'
Explanation:strstr searches for the first occurrence of a substring within another string.
Incorrect! Try again.
41What is the difference between printf("%s", str) and puts(str)?
A.No difference.
B.printf adds a newline automatically, puts does not.
C.puts adds a newline automatically, printf does not.
D.puts can format output, printf cannot.
Correct Answer: puts adds a newline automatically, printf does not.
Explanation:puts(str) prints the string and automatically appends a newline character (\n) at the end. printf("%s") simply prints the string.
Incorrect! Try again.
42Consider char *str = "Hello";. What is valid?
A.str[0] = 'h';
B.str = "World";
C.*str = 'M';
D.None of the above
Correct Answer: str = "World";
Explanation:str is a pointer variable, so it can be reassigned to point to a different string literal. Modifying the content (options A and C) of a string literal is undefined behavior.
Incorrect! Try again.
43What is the purpose of void * in malloc?
A.To allocate memory for void types only
B.To act as a generic pointer type that can be cast to any type
C.To indicate the function returns nothing
D.To create a null pointer
Correct Answer: To act as a generic pointer type that can be cast to any type
Explanation:malloc needs to be able to allocate memory for ints, floats, structs, etc. returning void * allows the user to cast it to whatever specific pointer type they need.
Incorrect! Try again.
44What is the priority of *ptr++?
A.Increment ptr, then dereference
B.Dereference ptr, then increment the value pointed to
C.Dereference ptr, then increment the pointer
D.Undefined
Correct Answer: Dereference ptr, then increment the pointer
Explanation:Postfix ++ has higher precedence than *. However, postfix happens after the value is used. So it fetches the value at ptr, then increments the address stored in ptr.
Incorrect! Try again.
45Which of the following creates a pointer to a pointer (Double Pointer)?
A.int **p;
B.int &p;
C.int p;
D.int p**;
Correct Answer: int **p;
Explanation:A double pointer creates a pointer that stores the address of another pointer. Syntax is type **name.
Incorrect! Try again.
46Why is free() necessary in dynamic memory allocation?
A.To initialize the memory
B.To return memory to the heap for reuse
C.To clear the contents of the variables
D.To delete the pointer variable
Correct Answer: To return memory to the heap for reuse
Explanation:Memory allocated on the heap persists until explicitly freed. free() returns this memory to the system (heap) so it can be reallocated, preventing leaks.
Incorrect! Try again.
47How do you read a string with spaces using scanf?
A.scanf("%s", str);
B.scanf("%[^
]s", str);
C.scanf("%s space", str);
D.scanf("% line", str);
Correct Answer: scanf("%[^
]s", str);
Explanation:The scanset %[^ ] tells scanf to read all characters until a newline character is encountered, effectively reading strings with spaces.
Incorrect! Try again.
48If int arr[] = {1, 2, 3}; and int *p = arr;, what is p[1]?
A.1
B.2
C.3
D.Address of 2
Correct Answer: 2
Explanation:Pointers can be indexed like arrays. p[1] is equivalent to *(p + 1), which accesses the second element of the array.
Incorrect! Try again.
49Which operator accesses a member of a structure using a pointer to that structure?
A..
B.->
C.*
D.&
Correct Answer: ->
Explanation:The arrow operator -> is used to access structure members when working with a pointer to the structure (e.g., ptr->member).
Incorrect! Try again.
50What is the output of printf("%d", *&a) if a = 10?
A.Address of a
B.10
C.Garbage
D.Error
Correct Answer: 10
Explanation:& gets the address, and * dereferences it. They effectively cancel each other out, returning the value of a.