Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

1. What is Array?

 
●  Collection of different type of elements
●  Collectionof similar type of elements
●  None of the above
●  Both A and C
ANSWER B
2. What are the Types of Arrays? 
●  int, float, char, double
●  struct, enum
●  long
●  All the above
ANSWER D
3. Assume the output of below code: 
"#include <stdio.h>
void f(int a[2][])
{
a[0][1] = 3;
int i = 0, j = 0;
for (i = 0;i < 2; i++)
for (j = 0;j < 3; j++)
printf(""%d"", a[i][j]);
}
void main()
{
int a[2][3] = {0};
f(a);
}"
●  compile time error
●  All junk values
●  0 Only
●  Runtime error
ANSWER A
4. Let x be an array. Which of the following are illegal 
●  x++
●  x+1
●  x*2
●  none of these
ANSWER A
5. Predict the output of below code: 
#include "stdio.h"
#include "stdlib.h"
int main(int argc, char *argv[]) {
char temp[20];
gcvt(23.45,2, temp);
printf("%s", temp);
return 0;
}
●  Output : 0.4
●  Output : 24.4
●  Output : 25.4
●  Output : 23
ANSWER D
6. Predict the output of below code: 
#include‹stdio.h›
int main()
{
struct site
{
char name[] = "GeeksforGeeks";
int no_of_pages = 200;
};
struct site *ptr;
printf("%d",ptr->no_of_pages);
printf("%s",ptr->name);
getchar();
return 0;
}
 GeeksforGeeks
●  Compilation Error
●  Runtime Error
●  Geeks
 View Answer B
7. Size of the array need not be specified, when 
●  It is a declaratrion
●  Initialization is a part of definition
●  It is a formal parameter
●  All the above
 View Answer B
8. The maximum number of dimension an array can have in C is 
●  compiler dependent
●  Only 2
●  Only 3
●  Only 4
 View Answer A
9. Comment on the below statements with respect to A and B 

int *a1[8];
int *(a2[8]);
A. Array of pointers
B. Pointer to an array

●  a1 is A, a2 is B
●  a1 is B, a2 is A
●  a1 is A, a2 is A
●  a1 is B, a2 is B
 View Answer C
10. Syntax of accessing the seventh element 
●  a{7}
●  a(7)
●  a"7"
●  a[7]
 View Answer D
11. Predict the output of below code: 
#include<stdio.h>
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
●  2,5,15
●  3, 2, 15
●  1,2,5
●  12,15,1
 View Answer B
12. What is the value of a[4]? 
int a[5]={1,2,4,1,0}

●  1 .
●  10 .
●  0 .
●  Error
 View Answer C
13. What is the output of C program with arrays? 

int main()
{
int a[3] = {20,30,40};
int b[3];
b=a;
printf("%d", b[0]);
}

●  Compiler Error
●  Output : 20
●  Output : 30
●  Output : 0
 View Answer A
14. If a two dimensional array is used as a formal parameter, then 
●  the first subscript must be left empty
●  the first (row) subscript may be left empty
●  both the subscripts must be left empty
●  both the subscripts may be left empty
 View Answer B
15. applications of a multidimensional array 
●  Matrix-Multiplication
●  Minimum Spanning Tree
●  Finding connectivity between nodes
●  All the above
 View Answer D
16. Predict the output of below code: 
#include <stdio.h>
int main()
{
int ary[2][3][4], j = 20;
ary[0][0] = &j;
printf("%d\n", *ary[0][0]);
}
●  Junk Value
●  No output
●  Compile time Error
●  Address of j
 View Answer C
17. Predict the output of below code: 
#include<stdio.h>
int main()
{
int arr[5], i=0;
while(i<5)
arr[i]=++i;
for(i=0; i<5; i++)
printf("%d, ", arr[i]);
return 0;
}
●  1,2,3,4
●  Garbage value, 1, 2, 3, 4,
●  2,4
●  none of these
 View Answer B
18. C does no automatic array bound checking. This is 
●  True.
●  False.
●  C's asset
●  C's shortcoming
 View Answer D
19. If n has the value 3, then the statement 
●  assigns 4 to a [4]
●  what is assigned is compiler-dependent
●  assigns 4 to a [5]
●  assigns 4 to a [6]
 View Answer B
20. Predict the output of below code: 

#include<stdio.h>
int main()
{
int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};
printf("%u, %u\n", a+1, &a+1);
return 0;
}

●  65430, 43569
●  65239, 64763
●  65480, 65496
●  61123, 74123
 View Answer C
21. Are the expressions arr and &arr same for an array of 10 integers? 
●  Yes
●  No
 View Answer B
22. Pick out the output 

#include <stdio.h>
int main()
{
foo(ary);
}
void foo(int **ary)
{
int i = 10, k = 10, j = 2;
int *ary[2];
ary[0] = &i;
ary[1] = &j;
printf("%d\n", ary[0][1]);
}

●  compile time error


●  Runtime error
●  Output : 20
●  Undefined Behaviour
 View Answer D
23. Point the correct statement 
●  An array element may be an array by itself
●  Strictly speaking C supports 1-dimensional arrays only
●  Both A and C
●  Array elements need not occupy contiguous memory locations
 View Answer C
24. Choose the correct statements 
●  An array size can not changed once it is created.
●  Array element value can be changed any number of times
●  To access Nth element of an array students, use students[n-1] as the starting index
is 0.
●  ALL of these
 View Answer D
25. Predict the output of below code: 
#include<stdio.h>
int main()
{
int arr[1]={10};
printf("%d\n", 0[arr]);
return 0;
}

●  Output : 1
●  Output : 10
●  Output : 6
●  Output : 8
 View Answer B
26. Predict the output of below code: 

int main()
{
char a[2][3][3] = {'g','e','e','k','s','f','o',
'r','g','e','e','k','s'};
printf("%s ", **a);
getchar();
return 0;
}

●  Geeks
●  Error
●  geeksforgeeks
●  No Output
 View Answer C
27. If storage class is missing in the array definition, by default it will be taken to be 
●  either automatic or external depending on the place of occurrence
●  static
●  automatic
●  external
 View Answer A
28. The information about an array used in a program will be sorted in 
●  Static table
●  Dope vector
●  Activate Record
●  Both A and C
 View Answer B
29. Predict the output of below code: 
#include <stdio.h>
void f(int a[][])
{
a[0][1] = 3;
int i = 0, j = 0;
for (i = 0;i < 2; i++)
for (j = 0;j < 3; j++)
printf("%d", a[i][j]);
}
void main()
{
int a[2][3] = {0};
f(a);
}

●  0 3 0 0 0
●  Junk junk junk
●  Compile time error
●  No output
 View Answer C
3 What does the following declaration mean?

int (*ptr)[10];

A. ptr is array of pointers to 10 integers

B. ptr is a pointer to an array of 10 integers

C. ptr is an array of 10 integers

D. ptr is an pointer to array


Answer: Option B

Top of Form
 

Bottom of Form

HomeAptitudeLogicalVerbalCurrent
AffairsGKEngineeringInterviewOnline TestsPuzzles
C Programming :: Arrays
Home » Engineering » C Programming » Arrays » General Questions
Exercise :: Arrays - General Questions
Arrays - General Questions
Arrays - Find Output of Program
Arrays - Point Out Correct Statements
Arrays - Yes / No Questions
1 What will happen if in a C program you assign a value to an array element
.  whose subscript exceeds the size of array?

A
The element will be set to 0.
.

B
The compiler would report an error.
.

C
The program may crash if some important data gets overwritten.
.

D
The array size would appropriately grow.
.
Answer: Option C
Explanation:
If the index of the array size is exceeded, the program will crash. Hence
"option c" is the correct answer. But the modern compilers will take care of
this kind of errors.
Example: Run the below program, it will crash in Windows (TurboC Compiler)
#include<stdio.h>

int main()
{
int arr[2];
arr[3]=10;
printf("%d",arr[3]);
return 0;
}
Since C is a compiler dependent language, it may give different outputs at
different platforms. We have given the Turbo-C Compiler (Windows) output.
Please try the above programs in Windows (Turbo-C Compiler) and Linux
(GCC Compiler), you will understand the difference better.
View Answer Discuss in Forum Workspace Report

2 What does the following declaration mean?



int (*ptr)[10];

A
ptr is array of pointers to 10 integers
.

B
ptr is a pointer to an array of 10 integers
.

C
ptr is an array of 10 integers
.
D
ptr is an pointer to array
.
Answer: Option B
Explanation:
No answer description available for this question. Let us discuss.
View Answer Discuss in Forum Workspace Report

3 In C, if you pass an array as an argument to a function, what actually gets


1  passed?

A
Value of elements in array
.

B
First element of the array
.

C
Base address of the array
.

D
Address of the last element of array
.
Answer: Option C
Bottom of Form

34
What will happen if in a C program you assign a value to an array element
whose subscript exceeds the size of array?

A
The element will be set to 0.
.

B
The compiler would report an error.
.

C
The program may crash if some important data gets overwritten.
.

D
The array size would appropriately grow.
.
Answer: Option C
33)What is a structure in C language.?
A) A structure is a collection of elements that can be of same data
type.
B) A structure is a collection of elements that can be of different
data type.
C) Elements of a structure are called members.
D) All the above
Answer [=] D
34) What is the size of a C structure.?
A) C structure is always 128 bytes.
B) Size of C structure is the total bytes of all elements of
structure.
C) Size of C structure is the size of largest element.
D) None of the above
Answer [=]B
37) What is the output of C program with structures.?

int main()
{
structure hotel
{
int items;
char name[10];
}a;
strcpy(a.name, "TAJ");
a.items=10;
printf("%s", a.name);
return 0;
}

A) TAJ
B) Empty string
C) Compiler error
D) None of the above
Answer [=]C
36) What is the output of C program.?

int main()
{
struct book
{
int pages;
char name[10];
}a;
a.pages=10;
strcpy(a.name,"Cbasics");
printf("%s=%d", a.name,a.pages);
return 0;
}

A) empty string=10
B) C=basics
C) Cbasics=10
D) Compiler error
Answer [=]C
37) Choose a correct statement about C structures.
A) Structure elements can be initialized at the time of declaration.
B) Structure members can not be initialized at the time of
declaration
C) Only integer members of structure can be initialized at the time
of declaraion
D) None of the above
Answer [=]B
38) Choose a correct statement about C structure.?

int main()
{
struct ship
{

};
return 0;
}

A) It is wrong to define an empty structure


B) Member variables can be added to a structure even after its
first definition.
C) There is no use of defining an empty structure
D) None of the above
Answer [=]
C
39) What is the output of C program.?

int main()
{
struct ship
{
int size;
char color[10];
}boat1, boat2;
boat1.size=10;
boat2 = boat1;
printf("boat2=%d",boat2.size);
return 0;
}

A) boat2=0
B) boat2=-1
C) boat2=10
D) Compiler error
Answer [=] C

40) What is the output of C program with structures.?

int main()
{
struct ship
{
char color[10];
}boat1, boat2;
strcpy(boat1.color,"RED");
printf("%s ",boat1.color);
boat2 = boat1;
strcpy(boat2.color,"YELLOW");
printf("%s",boat1.color);
return 0;
}
A) RED RED
B) RED YELLOW
C) YELLOW YELLOW
D) Compiler error
Answer [=] A
41) What is the output of C program with structures.?

int main()
{
struct tree
{
int h;
}
struct tree tree1;
tree1.h=10;
printf("Height=%d",tree1.h);
return 0;
}

A) Height=0
B) Height=10
C) Height=
D) Compiler error
Answer [=] B
42) Choose a correct statement about C structure elements.?
A) Structure elements are stored on random free memory
locations
B) structure elements are stored in register memory locations
C) structure elements are stored in contiguous memory locations
D) None of the above.
Answer [=] C
43) A C Structure or User defined data type is also called.?
A) Derived data type
B) Secondary data type
C) Aggregate data type
D) All the above
Answer [=] D
44) What are the uses of C Structures.?
A) structure is used to implement Linked Lists, Stack and Queue
data structures
B) Structures are used in Operating System functionality like
Display and Input taking.
C) Structure are used to exchange information with peripherals of
PC
D) All the above
Answer [=] D
45) What is the output of C program with structures.?
int main()
{
struct tree
{
int h;
int w;
};
struct tree tree1={10};
printf("%d ",tree1.w);
printf("%d",tree1.h);
return 0;
}

A) 0 0
B) 10 0
C) 0 10
D) 10 10
Answer [=]
C
46) What is the output of C program with structures.?

int main()
{
struct tree
{
int h;
int rate;
};
struct tree tree1={0};
printf("%d ",tree1.rate);
printf("%d",tree1.h);
return 0;
}
A) 0 0
B) -1 -1
C) NULL NULL
D) Compiler error
Answer [=] A
47) What is the size of the below C structure in TurboC?

int main()
{
struct books{
int pages;
char str[4];
}b;
printf("%d",sizeof(b));
return 0;
}

A) 5
B) 6
C) 7
D) 8
Answer [=] B
48) What is the output of C program with Structure pointer in TurboC.?

int main()
{
struct books{
int pages;
char str[4];
}*ptr;
printf("%d",sizeof(ptr));
return 0;
}

A) 2
B) 6
C) 7
D) 8
Answer [=] B

49) In a nested structure definition, with country.state.district statement,


memeber state is actually present in the structure.? (COUNTY, STATE,
DISTRICT structures)
A) district
B) state
C) country
D) None of the above
Answer [=] C
50) What is actually passed if you pass a structure variable to a function.?
A) Copy of structure variable
B) Reference of structure variable
C) Starting address of structure variable
D) Ending address of structure variable
Answer A

You might also like