You are on page 1of 7

Sources / sites

http://www.cquestions.com/2012/02/data-type-questions-in-c.html

http://www.indiabix.com/c-programming/pointers/

Directions

Step 1: Identify solution without any assistance (compiler, textbook, Google, etc).

Step 2: Research (textbook, Google), work (compiler), and implement the solution.

Step 3: Compare your expected result and actual result.

Resolve the difference by collaborating and corroborating with your classmates. If still not resolved, check with me.

Due to compilers using different standards and some not conforming to standards, it is possible for the output to be different or
incorrect. So its important that you identify the correct version and use that as reference for the exam preparation.

Some questions might refer to topics we have not covered yet for the current exam. Save it for the future exam.

If the code generates a compilation error, then identify the reason for the error and fix it.
Questions Lesson(s) Learned
1 What will be the output of the program if the array begins 4300 in memory? https://www.indiabix.com/c-
#include<stdio.h> programming/arrays/044001
void main(void) 3 garbage values

{ 4300 4300 4300


int arr[]={2, 3, 4, 1, 6}; 3 same values
printf("%u, %u, %u\n", arr, &arr[0], &arr);
}

2 Which of the following statements are correct about 3 used in the program? B
int num[3];
num[3]=6;
A. In the first statement 3 specifies a particular element, whereas in the
second statement it specifies a type.
B. In the first statement 3 specifies an array size, whereas in the second
statement it specifies a particular element of array.
C. In the first statement 3 specifies a particular element, whereas in the
second statement it specifies an array size.
D. In both the statement 3 specifies array size.

3 Which of the following statements are correct about an array? 1. The array int num[26]; can store 26
1: The array int num[5]; can store 5 elements. elements. This statement is true.
2: The expression num[1] designates the very first element in the array.
3: It is necessary to initialize the array at the time of declaration. 2. The expression num[1] designates the
4: The declaration num[SIZE] is allowed if SIZE is a macro. very first element in the array. This
statement is false, because it designates
the second element of the array.

3. It is necessary to initialize the array at


the time of declaration. This statement is
false.

4. The declaration num[SIZE] is allowed


if SIZE is a macro. This statement is true,
because the MACRO just replaces the
symbol SIZE with given value.

Hence the statements '1' and '4' are


correct statements
4 A pointer to a block of memory is effectively same as an array Yes, It is possible to allocate a block of
memory (of arbitrary size) at run-time,
A. True
using the standard library's malloc
B. False function, and treat it as an array.
5 What will happen if in a C program you access an array element whose subscript If the index of the array size is exceeded,
exceeds the size of array? the program will crash. Hence "option c"
A. The element will be set to 0. is the correct answer. But the modern
B. The compiler would report an error. compilers will take care of this kind of
C. The program may crash. errors.
D. The array size would appropriately grow.

6 Which of the following correctly declares an array? A


A. int anarray[10];
B. int anarray;
C. anarray{10};
D. array anarray[10];
7 What is the outcome/output of the following C program, if any? Error at assigning world to array
#include<stdio.h>
void main(void){
char arr[10];
arr = "world";
printf("%s",arr);
}
8 What will be output when you execute following c code? [row][column]
#include<stdio.h> 024
void main(void){ 135
char data[3][2]={0,1,2,3,4,5}; 2
printf("%d",data[1][0]);
}
9 What will be output when you will execute following c code? B
#include<stdio.h> Two non existent or declared functions
void main(void){ bring 0
int x[5]={5}; 00
printf("%d %d",x[1],x[9]);
}
Choose all that apply:
(A) 0 Garbage
(B) 00
(C) run time error
(D) Compilation error
(E) Garbage Garbage

10 What is the consistent outcome/output of the following C program, if any? 01234


#include<stdio.h> “garbage”,1,2,3,4
Ask prof
void main(void)
{
int arr[5], i=0;
while(i<5)
arr[i]=++i;

for(i=0; i<5; i++)


printf("%d, ", arr[i]);
}
Pay attention to value of i
11 In C, if you pass an array as an argument to a function, what actually gets
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

12 What is the outcome/output of the following C program, if any? 5

#include<stdio.h>
void main(void){
char data[2][3][2]={0,1,2,3,4,5,6,7,8,9,10,11};
printf("%d",data[0][2][1]);
}
Intentionally left blank.

You might also like