question

$$ANON_USER$$ avatar image
0 Votes"
$$ANON_USER$$ asked Viorel-1 answered

Unclear about the difference in address shown by the compiler.

I defined 4 integers variable in my C program and then took print of addresses of all these four variables, what i saw is, "It is showing difference of 12 decimal numbers between two addresses but we know that size of 'int' data type in VS2019 is 4 byte". So please help me out.
Here is the C source code-

include<stdio.h>

int main()
{
int i = 10, j = 12, k = 90, l = 76;
printf("%d\t%d\t%d\t%d\n", &i, &j, &k, &l);
return 0;
}

c++
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The proper way to print an address with printf is to use %p in the format string.

0 Votes 0 ·

Yes i know it

0 Votes 0 ·

1 Answer

Viorel-1 avatar image
1 Vote"
Viorel-1 answered

Try selecting the Release configuration, because in Debug configuration the compiler seems to insert some additional spaces used by Debugger.

But it is up to compiler to allocate the variables.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Further to Viorel-1's observation the insertion of padding by the debugger for stack-based variables in a debug build is specified by this compiler setting - rtc-run-time-error-checks. In the project properties look at Configuration->C++->Code Generation->Basic Runtime Checks.


0 Votes 0 ·

Yes i got it, thanks a lot

0 Votes 0 ·