C array questions

C array questions

1. What will be the output of the following program. ?

#include< stdio.h >
int
main()
{
char a[]="programmingknow", a[]="programmingknow";
if(a==b)
{
printf("Strings Equal");
}
return 0;
}

a. no output
b. compile time Error
c. Run time Error
d. Strings Equal

Show Answer

The correct option is (a)
Explanation:
In this program we comparing the base address of ‘a’ and ‘b’ and that are not same. Therefore the program has No output.

2.If pass an array as an arguments to a any function, what the actually get passed ?

a. Base address of the Array
b. First element of the array
c. values of the array elements
d. Address of the last element of array

Show Answer

The correct option is (a)
Explanation:
In C programming when we pass an array as an argument to the function , then the Base address of the array passed.

3. What is the right way to initialize an array ?

a. int num[6] = { 7, 7, 18, 3, 45, 5 };
b. int n{} = { 2, 3, 6, 5, 1, 1 };
c. int n{6} = { 2, 2, 13 };
d. int n(6) = { 2, 2, 22, 5, 2, 2 };

Show Answer

The correct option is (a)
Explanation:
Option b,c,d are wrong because in these options array declaration syntax is wrong, only square brackets [] are used to declare array.

4. What is the output of the following program ?

#include< stdio.h >
int
main()
{
char ptr;
char arr[10]={1,2,3,4,5,6,9,8};
ptr=(arr+1)[5];
printf(“%d”,ptr);
return 0;

a. 4
b. 6
c. 5
d. Error

Show Answer

The correct option is (b)
Explanation:
a[i] is equals to *(a + i), so (arr+ 1)[5] is *(arr + 1 + 5), i.e. arr[6].

5. An Array elements always stored in ___________ memory location ?

a. Sequential
b. Sequential and random
c. Random
d. Non of these

Show Answer

The correct option is (a)
Explanation:

6. What will be print after execution of the program?

#include< stdio.h >
int
main()
{
int num[10]={4,5,6,7,8};
printf(“%d”,num[5]);
return 0;
}

a. Garbage value
b. 0
c. 6
d. 8

Show Answer

The correct option is (b)
Explanation:
When an array is initialized at the time of declaration then the remaining elements of the array is initialized to 0 by the compiler default.