WorksheetsC Pointers Quiz
Total questions: 66
Worksheet time: 34mins
What does the dereference operator (*) do?
It compares two pointers
It retrieves the value at the address stored in a pointer
It assigns a value to a pointer
It creates a pointer
What is the size of a pointer on a 64-bit system?
2 bytes
4 bytes
8 bytes
16 bytes
What is a NULL pointer?
A pointer that points to a valid memory location
A pointer that does not point to any memory location
A pointer that points to a function
A pointer that points to an array
What is a wild pointer?
A pointer that points to a valid memory location
A pointer that points to a function
A pointer that has not been initialized
A pointer that points to NULL
What is a dangling pointer?
A pointer that points to a valid memory location
A pointer that points to a memory location that has been freed
A pointer that points to NULL
A pointer that has not been initialized
What is pointer arithmetic?
Comparing two pointers
Incrementing or decrementing pointer addresses
Assigning values to pointers
Performing mathematical operations on pointer values
How can you access array elements using pointers?
By using the dereference operator only
By using the sizeof operator
By using pointer arithmetic
By using the array name directly
What is a constant pointer?
A pointer that cannot be modified
A pointer that points to a constant value
A pointer that can be reassigned
A pointer that points to a variable
What is a function pointer?
A pointer that points to an array
A pointer that cannot be modified
A pointer that points to a variable
A pointer that stores the address of a function
What is the purpose of the malloc() function?
To allocate memory dynamically
To free allocated memory
To initialize memory
To check memory size
What does the free() function do?
Allocates memory
Frees allocated memory
Initializes memory
Checks memory size
What happens if you dereference an uninitialized pointer?
It will return 0
It will return NULL
It will cause a segmentation fault
It will return a random value
What is the output of printf("%p", ptr) if ptr is a pointer to an integer?
The address of the integer
The size of the integer
The type of the integer
The value of the integer
What is the relationship between arrays and pointers in C?
Pointers cannot point to arrays
Array names act like pointers to the first element
Arrays and pointers are the same
Arrays cannot be accessed using pointers
What is the purpose of the realloc() function?
To allocate new memory
To change the size of previously allocated memory
To initialize memory
To free memory
What is the output of *ptr if ptr points to an integer variable with value 10?
The address of the variable
NULL
0
10
What is the main advantage of using pointers?
They are easier to understand
They are faster than arrays
They allow dynamic memory allocation
They simplify code
What is a pointer to a pointer?
A pointer that points to an array
A pointer that cannot be modified
A pointer that points to another pointer
A pointer that points to a variable
What is the output of printf("%d", *(&var)) if var is an integer variable with value 5?
The address of var
NULL
0
5
What is the effect of using an invalid pointer?
It will have no effect
It will return a default value
It may cause a program crash
It will return NULL
What is the correct way to initialize a pointer?
int *ptr = var;
int *ptr = 0;
int *ptr = NULL;
int *ptr = &var;
What does the & operator do in C?
Declares a pointer variable
Returns the address of a variable
Dereferences a pointer
Multiplies two variables
How do you declare a pointer to an integer in C?
int p;
int *p;
int &p;
pointer int p;
What does the * operator do when used with pointers?
Declares a pointer
Returns the address of a variable
Dereferences a pointer to access the value
Multiplies two values
What is the output of the following code?
5
Address of c
Garbage value
Compilation error
Which of the following statements is incorrect?
pc = &c;
*pc = c;
pc = c;
*pc = &c;
Given the array declaration int x[5];, what does x represent?
The value of the first element
The address of the first element
The size of the array
An undefined value
Which expression is equivalent to x[i]?
*(x + i)
x + i
&x + i
*x + i
What is the output of the following code?
1
2
3
4
What happens when you assign the address of a variable to a pointer?
The pointer stores the value of the variable
The pointer stores the address of the variable
The variable becomes a pointer
Compilation error
Which of the following is a common mistake when working with pointers?
Assigning an address to a pointer
Dereferencing a pointer before assigning it an address
Using & to get the address of a variable
Using * to access the value pointed by a pointer
Pointers refer to
Memory Address
Value in Memory
All the above
Computer memory locations are
Bi linear
Linear
Non Linear
Computer address values in reality are in
Decimal
Binary
Hexadecimal
C code
One Byte is equal to
8 bits
4 bits
2 bits
1 bit
An integer requires
One byte of memory
4 bytes of memory
8 bytes of memory
printf("%d", &C), prints
value of C
Address of C
Error message
None of the above
If 5 is added to the address value 'A' of an integer variable the new address is
A +5
A+ 10
A+ 20
Data insufficient
In a C Program if
int a = 5;
Int *ptr = &a;
then the printf statement with
&a, a, *ptr , ptr
adrress, Value, Value, Adress
address, value, value, value
all address
All values
In a C Program if
int a = 5;
Int *ptr = &a;
printf ("%d" , ptr)
gives
5
address of a
address of ptr
none
A double pointer points
address of an integer
address of a pointer
value stored in the memory
None
In a C program,
int a = 20;
*ptr = &a;
**dptr = &ptr;
printf ("%d", **dptr);
prints
address of a
address of ptr
value of a
address of dptr
What do the following declaration signify?
char *arr[10];
arr is a array of 10 character pointers.
arr is a array of function pointer.
arr is a array of characters.
arr is a pointer to array of characters.
What is the output of C Program.?
int main()
{
char grade[] = {'A','B','C'};
printf("GRADE=%c, ", *grade);
printf("GRADE=%d", grade);
}
GRADE=some address of array, GRADE=A
GRADE=A, GRADE=some address of array
GRADE=A, GRADE=A
Compiler error
What is the output of C program.?
int main()
{
char grade[] = {'A','B','C'};
printf("GRADE=%d, ", *grade);
printf("GRADE=%d", grade[0]);
}
A A
65 A
65 65
None of the above
What is the output of C program with arrays and pointers.?
int main()
{
int a[3] = {20,30,40};
printf("%d", *(a+1));
}
20
30
40
Compiler error
What is the output of following program?
# include <stdio.h>
void fun(int x)
{
x = 30;
}
int main()
{
int y = 20;
fun(y);
printf("%d", y);
return 0;
}
30
20
Compiler Error
Runtime Error
Output of following program?
# include <stdio.h>
void fun(int *ptr)
{
*ptr = 30;
}
int main()
{
int y = 20;
fun(&y);
printf("%d", y);
return 0;
}
20
30
Compiler Error
Runtime Error
Pointers refer to
Memory Address
Value in Memory
All the above
Computer memory locations are
Bi linear
Linear
Non Linear
Computer address values in reality are in
Decimal
Binary
Hexadecimal
C code
One Byte is equal to
8 bits
4 bits
2 bits
1 bit
printf("%d", &C), prints
value of C
Address of C
Error message
None of the above
A double pointer points
address of an integer
address of a pointer
value stored in the memory
None
What is the output of following program?
#include<stdio.h>
int main()
{
int *ptr, a=5;
ptr = &a;
*ptr += 1;
printf("%d, %d", *ptr, a);
return 0;
}
5,5
5,6
6,5
6,6
The value printed by the following program is
10
20
30
40
How do you declare a pointer to a function in C?
func_ptr *function_name
function_name *func_ptr
func_ptr function_name
function_name func_ptr
What will be the output of the following C code?
void main() {
int a[] = {1,2,3,4,5}, p;
p = a;
++p;
printf("%d ", p);
p += 2;
printf("%d ", p);
}
24
34
22
23
What is the output of the following C code?
char *ptr;
char mystring[] = "abcdefg";
ptr = myString;
ptr += 5;
fg
efg
defg
cdefg
bcdefg
What will be the output of the following C code?
void main() {
char p;
p = "Hello";
printf("%c\n", &*p);
}
Hello
H
Some address will be printed
None of these
What will be the output of the program if the array begins at 1000 and each integer occupies 2 bytes?
void main() {
int i = 10;
void p = &i;
printf("%f\n", (float *)p);
}
Error
10
0.0000000
None of these
In a C Program if
int a = 5;
Int *ptr = &a;
then the printf statement with
&a, a, *ptr , ptr
adrress, Value, Value, Adress
address, value, value, value
all address
All values
In a C program,
int a = 20;
*ptr = &a;
**dptr = &ptr;
printf ("%d", **dptr);
prints
address of a
address of ptr
value of a
address of dptr
What will be output?
int i=10;
int *p;
p=&i;
i+=5;
printf("\n i=%d *p=%d", i,*p)
i=10, *p=10
i=10, *p=15
i=15, *p=15
i=15, *p=10
# include <stdio.h>
void fun(int *p){
*p = 10;
}
int main()
{
int y = 5;
fun(&y);
printf("%d", y);
return 0;
}
10
5
error
address
int main()
{
int arri[] = {1, 2 ,3};
int *ptri = arri;
printf("%d ", sizeof(arri));
printf("%d ", sizeof(ptri));
return 0;
}
3 3
12 12
12 4
4 4
