Collection of most Frequently Asked Question for Array and Pointer in C Programing in Practical viva in Engineering or job interview to a candidate.
C Programming Basic Questions
Array in Embedded C
1.What is the output of the program?
main()
{
int a[] = {0, 0X4, 4, 9};
int i = 2;
printf(“%d %d”, a[i], i[a]);
}
a) 0 2
b) 2 0
c) 4 0
d) 4 4
ANSWER: D
2.What is the value of i in the following code?
main()
{
int i = strlen(“BLUE”) + strlen(“PURPLE”) / strlen(red) – strlen(green);
printf(“%d”, i);
}
a) 1
b) -2
c) -1.666
d) -1
ANSWER: A
3.What is the output of the following code?
int cap(int);
main()
{
int n; n = cap(6);
printf(“%d”, n);
}
int cap(int n)
{
if (n <=1) return 1;
else return(cap(n -3) + cap(n-1));
}
a) 7
b) 8
c) 9
d) 10
ANSWER: C
4.Which of the following is the correct way to access the last element of the array arr, if arr is declared as int arr[3][3][4]?
a) *(*( (arr + 2 ) + 2) + 4)
b) *(*( *(arr + 3 ) + 3) + 4)
c) *(*( *(arr + 2 ) + 3) + 4)
d) *(*( *(arr + 2 ) + 2) + 3)
ANSWER: D
5.Which of the following is the correct output for the program given below?
#include <stdio.h>
int main()
{
int size;
scanf(“%d”, &size);
int arr[size];
for(i =1; I <= size; i++)
{
scanf(“%d”, arr[i]);
printf(“%d”, arr[i]);
}
return 0;
}
a) The code is erroneous science the subscript for array used in for loop is in the range 1 to size.
b) The code is erroneous science the values of array are getting scanned through a loop.
c) The code is erroneous science the statement declaring array is invalid.
d) The code is correct and runs successfully.
ANSWER: C
CONTINUE READING » C Programming Basic Questions
Array in Embedded C
1.What is the output of the program?
main()
{
int a[] = {0, 0X4, 4, 9};
int i = 2;
printf(“%d %d”, a[i], i[a]);
}
a) 0 2
b) 2 0
c) 4 0
d) 4 4
ANSWER: D
2.What is the value of i in the following code?
main()
{
int i = strlen(“BLUE”) + strlen(“PURPLE”) / strlen(red) – strlen(green);
printf(“%d”, i);
}
a) 1
b) -2
c) -1.666
d) -1
ANSWER: A
3.What is the output of the following code?
int cap(int);
main()
{
int n; n = cap(6);
printf(“%d”, n);
}
int cap(int n)
{
if (n <=1) return 1;
else return(cap(n -3) + cap(n-1));
}
a) 7
b) 8
c) 9
d) 10
ANSWER: C
4.Which of the following is the correct way to access the last element of the array arr, if arr is declared as int arr[3][3][4]?
a) *(*( (arr + 2 ) + 2) + 4)
b) *(*( *(arr + 3 ) + 3) + 4)
c) *(*( *(arr + 2 ) + 3) + 4)
d) *(*( *(arr + 2 ) + 2) + 3)
ANSWER: D
5.Which of the following is the correct output for the program given below?
#include <stdio.h>
int main()
{
int size;
scanf(“%d”, &size);
int arr[size];
for(i =1; I <= size; i++)
{
scanf(“%d”, arr[i]);
printf(“%d”, arr[i]);
}
return 0;
}
a) The code is erroneous science the subscript for array used in for loop is in the range 1 to size.
b) The code is erroneous science the values of array are getting scanned through a loop.
c) The code is erroneous science the statement declaring array is invalid.
d) The code is correct and runs successfully.
ANSWER: C