Arrays And Pointer in C Programming -Job Interview Frequently Asked Question

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


6.Which of the following is the correct output for the program given below?
#include <stdio.h>
int main()
{
int a[] = {10, 20, 30, 40, 50};
char *p;
p = ( char *)a;
printf(“%d”, *((int *)p + 3));
return 0;
}

a) 20 
b) 30
c) 40
d) 50
ANSWER: C

7.Which of the following is the correct output for the program given below?
#include <stdio.h>
int main()
{
static int a[] = {0, 1, 2, 3, 4};
static int *p[] = {a+2, a, a+4, a+3, a+1};
int **ptr;
ptr = p;
**++ptr;
printf(“%d %d”, **ptr, ptr - p);
return 0;
}

a) 2 1
b) 1 2
c) 0 1
d) 1 0
ANSWER: C

8.Which of the following could replace the ???? in the code above to print the index of the first occurrence of the letter o in s(in this case the value would be 1)?
Main()
{
Char s[] = “Vocal Point”;
Printf(“%d\n”, ????);
}

a) Strchr(s, ‘o’) –s
b) Strchr(s, “o”)
c) Strchr(s,’o’)
d) Strchr(s, “o”) – s
ANSWER: A

9.Which of the following statement are correct about an array?

a) The array int num[25]; can store 25 elements
b) The expression num[1] designated the very first element in the array
c) It is necessary to initialized the array at the time of deceleration
d) The expression num[15] designated the 16th element in the array
ANSWER: A and D

10.Which of the following is the correct output for the program given below?

#include <stdio.h>
Int main()
{
Int a[3][3][2] = {
{
6, 5
4, 3
2, 1
},
{
1, 2
3, 4
5, 6
},
{
5, 6
1, 2
3, 4
}
};
Printf(“%d %d %d”, *(*(*(a + 0)+2)+1), *(*(*(a +2)+1)+1), *(a[1][1]+1));
}

a) 2 2 2
b) 1 2 3
c) 3 2 1 
d) 1 2 4
ANSWER: D

11.Output of the following program

#include <stdio.h>
Int main()
{
Char a[] = “Visual C++”;
Char *b =”Visual C++”;
printf(“%d %d”, sizeof(a), sizeof(b));
return 0;
}

a) 11 11
b) 10 10
c) 11 4
d) 4 11
ANSWER: C

12.What will happen when the following program is executed?
#include <stdio.h>
Int main()
{
Int a[] ={21, 12, 34, 45, 56};
Int j;
For(j = 0; j <5; j++)
{
Printf(“%d”, *a);
a++;
}
return 0;
}

a) Error : ‘Expression Syntax’
b) Output : 21 12 34 45 56
c) Error : ++needs l-value
d) Output: 56 45 34 12 21
ANSWER: B


13. Which of the following macros would properly return the number of element in an array(not a pointer, an actual array)?

a) #define NUM_ELEM(x) (sizeof(x)/ sizeof(x[0])).
b) #define NUM_ELEM(x) (sizeof(x))
c) #define NUM_ELEM(x) (sizeof(x[0])/ sizeof(x)).
d) #include
ANSWER: A

14.What is the output of the program?

#include <stdio.h>
main()
{
char s1[] = “Ramko”;
char s2[] = “System”;
s1 = s2;
printf(“%s”, s1);
}

a) System
b) Run time error
c) Compile time error
d) None.
ANSWER: C

15.Which of the following is the correct output for the program give below?

#include <stdio.h>
int main()
{
int arr[5][5][5];
/* Assume base address of the arr to be 1000*/
printf(“%u %u % u %u”, arr+1, arr[1][1], arr[3][4], arr[4][3]);
return 0; 
}

a) 10100 10120 10380 10460
b) 10080 10100 10360 10460
c) 10100 10120 10360 10440
d) 10100 10120 10360 10460
ANSWER: A

16.Which of the following can also be used in place of num[i]?

a) * (num + i)
b) I[num]
c) * (i + num)
d) All of the above.
ANSWER: D

17. What is p in the following declaration?
Int (*p)[3][4];

a) P is a pointer to a 2-D array of 3 rows and 4 columns. 
b) P is a function pointer to a 2-D array of 3 rows and 4 columns.
c) P is a pointer to array of 4 elements.
d) None 
ANSWER: A

18.What will be the address of the arr[2][3] if arr is a 2-D long array of 4 rows and 5 columns and starting address of the array is 2000?

a) 2048
b) 2056
c) 2052
d) 2042
ANSWER: C

19.What will be the output of the following code?
#include <stdio.h>
Main()
{
Int a[10];
Printf(“%d”, ((a+9) + (a+1)));
}

a) Error : invalid pointer arithmetic 
b) 19 11
c) 10 10
d) None 
ANSWER: A

20.What is the output of the following program?
#include <stdio.h>
main()
{
char numbers[5][6] = {“zero”, “one”, “two”, “three”, “four”};
printf(“%s is %c”, &numbers[4][0], numbers[0][0]);
}

a) One is z
b) Two is z
c) Three is z
d) Four is z
ANSWER: D

Related

Programming 6237075139520525000

Post a Comment

SPAMMING will not be Appreciated.

emo-but-icon

Hot in week

Recent

Comments

Our Channel

Contact Us

Name

Email *

Message *

item