C Array MCQ
Q1) What is the output of C program with arrays and pointers.?
int main() { int size=4; int a[size]; a[0]=5;a[1]=6; a[2]=7;a[3]=8; printf("%d %d", *(a+2), a[1]); }
- 8 6
- 7 6
- 6 6
- Compiler error
Answer:- (B).
Explanations :variable size is already defined. So a[size] is allowed. *(a+2) == a[2].
Explanations :variable size is already defined. So a[size] is allowed. *(a+2) == a[2].
int main() { int ary(3)=[20,30,40]; printf("%d", a(1)); }
- 20
- 30
- 0
- Compiler error
Answer:- (D).
Explanations :Array should be declared and defined with Square Brackets. Use ary[2] instead of ary(2).
int ary[3]={20,30,40};
Explanations :Array should be declared and defined with Square Brackets. Use ary[2] instead of ary(2).
int ary[3]={20,30,40};
int main() { int rollno[3]=[1001,1002,1003]; printf("%d", rollno[1]); }
- 1002
- 1003
- address of 1002
- Compiler error
Answer:- (D).
Explanations :You should use Flower Brackets or Braces to define elements like {1,2,3}. It is wrong to use [1,2,3].
Explanations :You should use Flower Brackets or Braces to define elements like {1,2,3}. It is wrong to use [1,2,3].
int main() { char grade={'A','B','C'}; printf("%c", grade[0]); }
- A
- B
- 41
- Compiler error
Answer:- (D).
Explanations :Notice that char grade is an character variable, not Character array variable. So declare as char grade[] = {'A','B','C'};
Explanations :Notice that char grade is an character variable, not Character array variable. So declare as char grade[] = {'A','B','C'};
- By default Zero 0
- 1
- Depends on Storage Class
- None of the above.
Answer:- (C).
Explanations :For Automatic variables, default value is garbage. For static and global variables, default value is 0.
Explanations :For Automatic variables, default value is garbage. For static and global variables, default value is 0.
- Compiler error is thrown
- 0 value will be returned
- 1 value will be returned
- Some garbage value will be returned.
Answer:- (D).
Explanations :None
Explanations :None
int main() { int ary[9]; return 0; }
- 8
- 9
- 10
- None of the above
Answer:- (B).
Explanations :Array size is 9. So memory occupied by 9 integers are kept aside by the CPU.
Explanations :Array size is 9. So memory occupied by 9 integers are kept aside by the CPU.
int main() { int ary[9]; return 0; }
- -1, 8
- 0, 8
- 1,9
- None of the above
Answer:- (B).
Explanations :Array index starts with 0 and ends with 8 for a 9 Size array. ary[0] to ary[8] are meaningful.
Explanations :Array index starts with 0 and ends with 8 for a 9 Size array. ary[0] to ary[8] are meaningful.
- Yes. Through pointers.
- Yes. Through Call by Value.
- Yes. Through Call by Reference.
- None of the above.
Answer:- (D).
Explanations :No. You can not change the C Basic rules of Zero Starting Index of an Array.
Explanations :No. You can not change the C Basic rules of Zero Starting Index of an Array.
- You need not create so many separate variables and get confused while using.
- Using a single Array variable, you can access all elements of the array easily.
- Code maintainability is easy for programmers and maintainers.
- All the above.
Answer:- (D).
Explanations :None
Explanations :None
Copyright © 2022 Shineskill Software Pvt. Ltd., All rights reserved.