• closed by
2,382 views
1 1 vote
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;
}

2 Answers

0 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 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;
}
Position:
Show:

Related questions

2 2 votes
2 answers 2 answers
816
816 views
kvkumar asked Jun 6, 2016
816 views
#include<stdio.h int main(){ int a; if(a=printf("hello")) printf("gatecse%d",a); }
1 1 vote
1 answers 1 answer
2.2k
2.2k views
Sahil Vidyarthi asked Aug 23, 2014
2,206 views
Explain the output :-int b[3][4] = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}};int p;p = (int )b;cout << (long)*p << "\t" << (long)(*p+1) << "\t" << (long)(*p+2);//long is used...
1 1 vote
1 1 answer
1.6k
1.6k views
Prajwal Bhat asked Aug 19, 2016
1,649 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 1 vote
1 answers 1 answer
994
994 views
komal07 asked Jul 11, 2015
994 views
printf("xy","ab","mn") will printa)xy b)xy ab mn c)garbage value d) error