497 views

2 Answers

2 votes
2 votes

 Initially j have address of i . since j is integer type pointer , if we increment the j then  

The output will be next address of memory location where i is placed .

              268672      i =10
Answer = 268676       
1 votes
1 votes

let size of int =2 bytes

as j stores base address(starting ) incrementing oj j is calculated as

j=(base address of i)+(size of int)*count ,

in ur program count =1 , hence j= BA+2

e.g if base address is 1000 , j=1000+2=1002.

BUT WAIT YOUR PROGRAM IS NOT A VALID PROGRAM

even though compiler will print the address stored in j but incrementing k is invalid step in your program

Actually, incrementing/decrementing of the void* is undefined behavior, as void* means actually pointer to some type. Compiler doesn't know how should it increment a void* and seems to use the predefined value.

So before the incrementing, you have to cast it to a correct type.

Related questions

0 votes
0 votes
1 answer
1
Psnjit asked Jan 12, 2019
1,136 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 votes
0 votes
1 answer
2
Mr khan 3 asked Nov 3, 2018
977 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 votes
0 votes
0 answers
4
garvit_vijai asked Sep 2, 2018
683 views
Please explain the output for the following program: #include<stdio.h>int main() { int i = 100; int *a = &i; float *f = (float *)a; (*f)++; pri...