This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Address Arithmetic – 2”.
Pre-requisite for C Address Arithmetic MCQ set: Video Tutorial on C Pointers.
1. What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *s = "hello";
char *p = s * 3;
printf("%c\t%c", *p, s[1]);
}
a) h e
b) l e
c) Compile time error
d) l h
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *s= "hello";
char *p = s + 2;
printf("%c\t%c", *p, s[1]);
}
a) l e
b) h e
c) l l
d) h l
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
int main()
{
void *p;
int a[4] = {1, 2, 3, 8};
p = &a[3];
int *ptr = &a[2];
int n = p - ptr;
printf("%d\n", n);
}
a) 1
b) Compile time error
c) Segmentation fault
d) 4
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
int main()
{
void *p;
int a[4] = {1, 2, 3, 4};
p = &a[3];
int *ptr = &a[2];
int n = (int*)p - ptr;
printf("%d\n", n);
}
a) 1
b) Compile time error
c) Segmentation fault
d) 4
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a[4] = {1, 2, 3, 4};
int b[4] = {1, 2, 3, 4};
int n = &b[3] - &a[2];
printf("%d\n", n);
}
a) -3
b) 5
c) 4
d) Compile time error
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a[4] = {1, 2, 3, 4};
int *p = &a[1];
int *ptr = &a[2];
ptr = ptr * 1;
printf("%d\n", *ptr);
}
a) 2
b) 1
c) Compile time error
d) Undefined behaviour
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a[4] = {1, 2, 3, 4};
int *ptr = &a[2];
float n = 1;
ptr = ptr + n;
printf("%d\n", *ptr);
}
a) 4
b) 3
c) Compile time error
d) Undefined behaviour
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a[4] = {1, 2, 3, 4};
void *p = &a[1];
void *ptr = &a[2];
int n = 1;
n = ptr - p;
printf("%d\n", n);
}
a) 1
b) 4
c) Compile time error
d) Depends on the compiler
View Answer
Explanation: None.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for Computer Science Internship
- Practice BCA MCQs
- Watch Advanced C Programming Videos
- Practice Computer Science MCQs
- Buy Computer Science Books