retagged by
1,547 views
1 1 vote
#include <stdio.h>
int main() {
	short int a[10];
	int i=0;
	for(i=0;i<10;i++) 
		a[i] = 300 + i;
	char *c = (char*)a;
	printf("%d\n", *(c+4));
	int *n = (int*)a;
	printf("%d\n",*(n));
}

output ?

1 Answer

Best answer
3 3 votes

Initaily short int array will be filled like: short int take 16 bits to represent (assume)

0 1 2 3 4 5 6 7 8 9
300 301 302 303 304 305 306 307 308 309

NOw it is type casted in to character type .( take  8 bits)

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
44 256 45 256 46 256 47 256 48 256 49 256 50 256 51 256 52 256 53 256

Here pointer c point in start *(c+4)= skip 4 element from start = 46

int *n = (int*)a; depend on size of int if it is 16 bits then 
0 1 2 3 4 5 6 7 8 9
300 301 302 303 304 305 306 307 308 309

print n = 300

selected by
Position:
Show:

Related questions

0 0 votes
1 1 answer
1.7k
1.7k views
Psnjit asked Jan 12, 2019
1,693 views
main(){unsigned int i= 255;char *p= &i;int j= *p;printf("%d\n", j);unsigned int k= *p;printf("%d", k);} Both the outputs are -1. I have even tried with - int i = 255(3rd ...
0 0 votes
1 1 answer
1.8k
1.8k views
Mr khan 3 asked Nov 3, 2018
1,797 views
#include<stdio.h void fun(int *p,int *q) { p=q; *p=q; } int i=0,j=1; int main() { fun(&i,&j); printf("%d%d",i,j); }What will be the output of i and j in 16-bit C Compiler...
0 0 votes
1 1 answer
1.5k
1.5k views
sushmita asked Sep 30, 2018
1,524 views
What is the interpretation of following C declaration:char *(*( foo[][8])())[];(A) foo is array of 8 pointer to pointer to function returning pointer to array of pointer ...