Home Subjects C Programming Pointers

C Programming
Pointers

C language from basics to advanced placement prep

27 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–20 of 27
Topics in C Programming
Q.11 Easy Pointers
What is the output?
int arr[] = {10, 20, 30};
int *p = arr;
printf("%d %d", *(p+1), arr[1]);
A 20 20
B 10 20
C 20 10
D 30 30
Correct Answer:  A. 20 20
EXPLANATION

p+1 points to second element (20). arr[1] is also 20. Both print the same value.

Test
Q.12 Easy Pointers
What will be the size of the pointer variable on a 64-bit system?
int *ptr;
A 4 bytes
B 8 bytes
C Depends on int size
D 16 bytes
Correct Answer:  B. 8 bytes
EXPLANATION

On a 64-bit system, all pointers are 8 bytes regardless of the data type they point to.

Test
Q.13 Easy Pointers
What is the output of the following code?
int x = 5;
int *p = &x;
int **q = &p;
printf("%d", **q);
A 5
B Garbage value
C Address of x
D Compilation error
Correct Answer:  A. 5
EXPLANATION

q is a pointer to pointer p. **q dereferences p twice, giving the value of x which is 5.

Test
Q.14 Easy Pointers
Which of the following is a void pointer?
A A pointer that points to nothing
B A generic pointer that can point to any data type
C A pointer declared as void variable
D A pointer that has been deleted
Correct Answer:  B. A generic pointer that can point to any data type
EXPLANATION

void* is a generic pointer that can hold addresses of any data type and requires explicit typecasting when used.

Test
Q.15 Easy Pointers
What is the output of the following code?
int x = 20;
int *p = &x;
printf("%d", *p);
A Address of x
B 20
C Garbage value
D Compilation error
Correct Answer:  B. 20
EXPLANATION

The * operator dereferences the pointer p, accessing the value it points to, which is 20.

Test
Q.16 Easy Pointers
What does the & operator do when used with a variable?
A Returns the value of the variable
B Returns the address of the variable
C Creates a copy of the variable
D Deallocates memory
Correct Answer:  B. Returns the address of the variable
EXPLANATION

The & (address-of) operator returns the memory address of the variable.

Test
Q.17 Easy Pointers
What is the size of a pointer variable in a 64-bit system?
A 8 bytes
B 4 bytes
C Depends on data type
D 16 bytes
Correct Answer:  A. 8 bytes
EXPLANATION

In a 64-bit system, all pointers occupy 8 bytes regardless of the data type they point to.

Test
Q.18 Easy Pointers
What will be printed by the code: char *ptr = "Hello"; printf("%c", *ptr);
A H
B Hello
C e
D Error
Correct Answer:  A. H
EXPLANATION

ptr points to the first character of the string, so *ptr dereferences to 'H'. The %c format specifier prints a single character.

Test
Q.19 Easy Pointers
Which operator is used to get the address of a variable?
A * (asterisk)
B & (ampersand)
C -> (arrow)
D . (dot)
Correct Answer:  B. & (ampersand)
EXPLANATION

The & (address-of) operator returns the memory address of a variable.

Test
Q.20 Easy Pointers
Consider: int x = 10; int *p = &x; What does the expression *p represent?
A The address of x
B The pointer variable p
C The value stored in x
D The size of x
Correct Answer:  C. The value stored in x
EXPLANATION

The dereference operator (*) accesses the value at the address pointed to by p, which is the value 10.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips