C Practice Programs 2

If “a” is an array of 5 x 5 dimension, a[2][4] is same as

  1. **(a+3+4)
  2.  *(a+3)+*(a+4)
  3. **(a+3)+4
  4.  *(*(a+2)+4)

Ans: Option 4


What is the output of the following code.

void main()

{

int y[2][2] = {{1,2}, {3,4}};

int *p = y[1];

p = p + 1;

printf(“%d\n”,*p);

}

  1. 4
  2.  3
  3. The program does not compile
  4. Output is unpredictable

Ans: 1


What is the Name of the pointer int **p; ?

  1.  pointer to pointer
  2. double pointer
  3.  float pointer
  4.  integer pointer

Ans: Option 1


Comment on the following pointer declaration?

int *ptr, p;

  1. ptr is a pointer to integer, p is not.
  2. ptr and p, both are pointers to integer.
  3. ptr is pointer to integer, p may or may not be.
  4. ptr and p both are not pointers to integer.

Ans: 1


What is the output of the following program?

void main()

{

char y[10]=”abcedefghi”;

char *p = y;

p = p + 9;

printf(“%c\n”,*p);

}

  1.  i
  2.  Program will have runtime error
  3. Unpredictable
  4. No visible output

Ans: 1


Click here for C Language Online Training Course Curriculum


What is the output of the following program?

void main()

{

int a[]={23,45,67};

printf(“\n%d”,*a);

a++;

printf(“\n%d”,*a);

return 0;

}

And: Compile time error


What is the output of the following program?

void main()

{

int a[ ]={5,3,3,2,6};

printf(“%d\t%d”,sizeof(a+1),sizeof(a));

}

Ans: 2    10


What is the output of the following program?

void main()

{

char str[]=”abcdef”;

++str;

++*str;

puts(str);

}

Ans: Compile-time error


What is the output?

#include <stdio.h>

void main()

{

char s[3][6]={“Zero”,”one”,”Two”};

printf(“%s”,s[2]);

printf(“%c”,s[2][0]);

}

Ans: Two


What is the output of the following program?

void main()

{

int arr[3][3]={ 10,20,30};

printf(“\n %d”,sizeof(arr[1]));

printf(“\n %d”,sizeof(arr[1][0]));

}

Ans: 6   2


What is the output of the following program?

#include <stdio.h>

void main()

{

char str[]=”Test”;

if((printf(“%s”,str))==4)

printf(“Success”);

else

printf(“Hello”);

}

Ans: Test Success


Determine output:

#include <stdio.h>

void main()

{

char *p = NULL;

char *q = 0;

if(p)

printf(” p “);

else

printf(“nullp”);

if(q)

printf(“q”);

else

printf(” nullq”);

}

  1. p q
  2. Depends on the compiler
  3. x nullq where x can be p or nullp depending on the value of NULL
  4. nullp nullq

Ans: 4


Click here for C Language Online Training Course Curriculum