Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

C Programming :: Arrays

Home > C Programming > Arrays > General Questions

11. What will be output of the following "c" code?

#include
int main(){
static int a[][2][3]={0,1,2,3,4,5,6,7,8,9,10,11,12};
int i=-1;
int d;
d=a[i++][++i][++i]; printf("%d",d); return 0;
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

12. What is the output of the following 'C' program ?

#include
void main()
{
char str [7] = "Chennai";
printf("%s", str);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

13. What is the following 'C' program doing?

#include
void main ()
{
unsigned int m[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
unsigned char n, i;
scanf("%d", &n);
for (i=0; i <= 7; i++)
{
if(n & m[i])
printf("\nyes");
}}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

14. #include
void main( )
{
int a[] = {10,20,30,40,50},j,*p;
for(j=0; j<5; j++)
{
printf("%d" ,*a);
a++;
}
p = a;
for(j=0; j<5; j++)
{
printf("%d " ,*p);
p++;
}
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

Error is in line with statement a++.
The operand must be an lvalue and may be of any of scalar type for the any operator, array name only when subscripted is an lvalue. Simply array name is a non-modifiable lvalue.

Workspace

Tags:

No Tags on this question yet!

15. #include
void main ( )
{
static char *s[] = {"black", "white", "yellow", "violet"};
char **ptr[ ] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
**++p;
printf("%s",*--*++p + 3);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option D

Explanation:

an "array of char pointers" pointing to start of 4 strings.
Then we have ptr which is a pointer to a pointer of type char and a variable p which is a pointer to a pointer to a pointer of type char.
p hold the initial value of ptr, i.e. p = s+3. The next statement increment value in p by 1 , thus now value of p = s+2. In the printf statement the expression is evaluated *++p causes gets value s+1 then the pre decrement is executed and we get s+1-1 = s. the indirection operator now gets the value from the array of s and adds 3 to the starting address. The string is printed starting from this position.
=> The output is 'ck'.

Workspace

Tags:

No Tags on this question yet!

16. #include
void main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d..%d \n",*p,*q);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option D

Explanation:

p=&a[2][2][2] you declare only two 2D arrays.
but you are trying to access the third 2D(which you are not declared) it will print garbage values.
*q=***a starting address of a is assigned integer pointer. now q is pointing to starting address of a.if you print *q meAnswer:it will print first element of 3D array.

Workspace

Tags:

No Tags on this question yet!

17. #include
void abc(char a[]);
void main(){
char a[100];
a[0]='a';
a[1]='b';
a[2]='c';
a[4]='d';
abc(a);
}
void abc(char a[]){
a++;
printf("%c",*a);
a++;
printf("%c",*a);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option D

Explanation:

The base address is modified only in function and as a result a points to 'b' then after incrementing to 'c'
=> bc will be printed.

Workspace

Tags:

No Tags on this question yet!

18. What is the output for the following "c" program

#include
void main()
{
int arr2D[3][3];
printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) );
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option C

Explanation:

This is due to the close relation between the arrays and pointers.
N dimensional arrays are made up of (N-1) dimensional arrays.
arr2D is made up of a 3 single arrays that contains 3 integers each .
arr2D arr2D[1] arr2D[2] arr2D[3]

The name arr2D refers to the beginning of all the 3 arrays. *arr2D refers to the start of the first 1D array (of 3 integers) that is the same address as arr2D. So the expression (arr2D == *arr2D) is true (1). Similarly, *arr2D is nothing but *(arr2D + 0), adding a zero doesn't change the value/meaning. Again arr2D[0] is the another way of telling *(arr2D + 0). So the expression (*(arr2D + 0) == arr2D[0]) is true (1).
Since both parts of the expression evaluates to true the result is true.

Workspace

Tags:

No Tags on this question yet!

19. What is the output of the following C Program?

#include
void main()
{
char p[ ]="%d\n";
p[1] = 'c';
printf(p,65);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option D

Explanation:

Due to the assignment p[1] = 'c' the string becomes, "%c\n".
Since this string becomes the format string for printf and ASCII value of 65 is 'A'.

Workspace

Tags:

No Tags on this question yet!

20. What will be output of the following "c" code?

#include
#include
void main()
{
char *p="GOOD";
char a[ ]="GOOD";
printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p), sizeof(*p), strlen(p));
printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a));
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

sizeof(p) => sizeof(char*) => 2 sizeof(*p) => sizeof(char) => 1
Similarly,

sizeof(a) => size of the character array => 5

When sizeof operator is applied to an array it returns the sizeof the array and it is not the same as the sizeof the pointer variable. Here the sizeof(a) where a is the character array and the size of the array is 5 because the space necessary for the terminating NULL character should also be taken into account.

Workspace

Tags:

No Tags on this question yet!