Showing posts with label important. Show all posts
Showing posts with label important. Show all posts

Sunday, August 28, 2016

Some Important conceptual output based questions of Arrays and Pointers in C lnaguage

Some Important conceptual output based questions of Arrays and Pointers in C language 

1. 
void main()
{
   int Blog[]={1,2,3};
   printf("%d %d %d",Blog[1],Blog[2],Blog[3]);
}

Output: 2 3 0

Explanation: Here Blog[0],Blog[1] and Blog[2] will be initialized with 1,2 and 3 respectively. and rest are initialized with 0.

2.
void main()
{
   int Blog[]={33,44};
   printf("%x",Blog);
 }

Output: Base address of Blog

Explanation: The array name always holds the base address of an array. If we print *Blog then output will be the first value.

3.void main()
{
  int Blog[4]={22,33,44,55},*ptr,T;
  ptr=Blog;
  T=++(*ptr);
  printf("%d %d",*ptr,T);
 }

Ans: 23 23

Exlanation: *ptr points to the first element of an array Blog. After ++(*ptr) , the value 
of first element is increased by 1 that is 23 and also updated to the array. Hence the output will be 23 23.

4.
void main()
{
  int Blog[4]={22,33,44,55},*ptr,T;
  ptr=Blog;
  T=*(ptr++);
  printf("%d %d",*ptr,T);
 }

Ans: 33 22

Explanation: *ptr points to the first element of an array Blog. After *(ptr++), the pointer ptr points to next element that is second element of array but due to post increment the variable T contains the first element of an array Blog.