What will be output if you will execute following code?
#include<stdio.h>
#include<stdio.h>
int main(){
static int i,j,k;
int *(*ptr)[];
int *array[3]={&i,&j,&k};
ptr=&array;
j=i+++k+10;
++(**ptr);
printf("%d",***ptr);
return 0;
return 0;
}
Output: 10
Explanation:
In this example:
array []: It is array of size three and its content are address of integer.
ptr: It is pointer to array which content are address of integer.
Pictorial representation above declaration:Note: In the above figure upper part of box represent content and lower part represent memory address. We have assumed arbitrary address.
j=i+++k+10
=i++ + k+10
=0 +0 +10=10
***ptr = *** (&array) //ptr=&array
= **array //From rule *&p=p
//From rule array [0] =*(array+0) and ++ (**ptr)
=*array [1]
=*&j
=j
=10
What will be output if you will execute following code?
#include<stdio.h>
#include<stdio.h>
int main(){
int i,j,k;
int *(*ptr)[];
int *array[3]={&i,&j,&k};
ptr=&array;
j=i+++k+10;
++(**ptr);
printf("%d",***ptr);
return 0;
return 0;
}
Output: Compiler error
Explanation: Address of auto variable cannot be member of an array.
No comments:
Post a Comment