Questions on Pointers in C
By BYJU'S Exam Prep
Updated on: September 25th, 2023
Questions on Pointers in C are provided here for candidates who are actively preparing for the GATE CSE exam 2023. Questions on Pointers in C can provide a quick overview of the types of questions to be expected in the exam on this topic.
Pointers will be better understood by using objective-based MCQ questions and answers. Five specially picked questions are mentioned here ranging from basic to high-level questions on pointers in C for the GATE exam pattern. Attempt and get the detailed solution to questions on Pointers in C mentioned in this article.
Table of content
Question 1 on Pointers in C
Can you combine the following two statements into one?
char *p;
p= (char*) malloc (100);
- char p = *malloc(100);
- char *p = (char) malloc(100);
- char *p = (char*)malloc(100);
- char *p = (char *)(malloc*)(100);
Answer: C. char *p = (char*)malloc(100);
Solution:
Yes, the given two statements can be combined as follows: char *p = (char*)malloc(100);. It is following the syntax to allocate memory to a character pointer variable p.
Question 2 on Pointers in C
A pointer is?
- A keyword used to create variables
- A variable that stores the address of an instruction
- A variable that stores the address of another variable
- All of the above
Answer: C. A variable that stores the address of another variable
Solution:
A pointer variable is defined as a variable that is used to store the address of another variable. A pointer variable is denoted by the * operator also called as dereference operator.
Question 3 on Pointers in C
The operator used to get the value at the address stored in a pointer variable is?
- *
- &
- &&
- ||
Answer: A. *
Solution:
To obtain the value stored at the address in a pointer variable the * operator is used. “&” is denoted as the address operator in C. While “&&” and “||” are logical AND and logical OR operators in C.
Question 4 on Pointers in C
Consider the following code:
int a[10], *x, *y;
x = &a[5];
y = &a[7];
Which of the following statement is incorrect concerning pointers?
- y – x
- y – 3
- x + y
- x + 1
Answer: C. x+y
Solution:
Here, we check the options one by one.
Option A:
y here denotes the address of the 8th element of the array whereas x denotes the address of the 6th element of the array. So, the y – x operation can be easily calculated and it will produce the output 2.
Option B:
We can subtract 3 from the pointer y as then it would point to the 5th element of the array.
Option C:
We can’t perform the addition of x and y pointer, as adding these two pointers points to some garbage value.
Option D:
We can add 1 to the pointer x as then it would point to the 7th element of the array.
Hence, option C is the correct answer.
Question 5 on Pointers in C
Which of the following represents the below terminology?
“ x is a pointer to array which is containing 5 integer pointers.”
- int *x [5]
- int (*x) [5]
- int *(*x) [5]
- int x [5]
Answer: C. int *(*x) [5]
Solution:
The correct representation of x is a pointer to an array which is containing 5 integer pointers: int *(*x) [5].
☛ Related Questions: