closed by
1,007 views
1 votes
1 votes
closed as a duplicate of: solve it
#include <stdio.h>
int main() {
    int a;
    char *x;
    x= (char *) &a;
    a=512;
    x[0]=1;
    x[1]=2;
    printf("%d\n",a);
    return 0;
}
closed by

2 Answers

0 votes
0 votes
Output is 513 in a little endian machine. To understand this output, let integers be stored using 16bits. In a little endian machine, when we do x[0] = 1 and x[1] = 2, then umber a is changed to 00000001 00000010 which is representation of 513 in a little endian machine.
0 votes
0 votes
#include <stdio.h>
int main() {
    int a;
    char *x;
    x= (char *) &a;// here type casting as character pointer point only to character variable
    a=512;//00000000(at x[0]) 00000001(at x[1])  as little endian
    x[0]=1;// 00000001  00000001
    x[1]=2;// 00000001  00000010
    printf("%d\n",a);  ////513
    return 0;
}

Related questions

2 votes
2 votes
2 answers
1
kvkumar asked Jun 6, 2016
460 views
#include<stdio.h int main(){ int a; if(a=printf("hello")) printf("gatecse%d",a); }
1 votes
1 votes
1 answer
3
Prajwal Bhat asked Aug 19, 2016
1,078 views
#include<stdio.h>int main(){int a = 10, b = 20, c = 30, d = 40;printf("%d%d%d",a, b, c);printf("%d%d%d", d);return 0;}What is the Output and when I run it I am getting so...
1 votes
1 votes
1 answer
4
komal07 asked Jul 11, 2015
683 views
printf("xy","ab","mn") will printa)xy b)xy ab mn c)garbage value d) error