Int Address in memory increasing by 4


int main()
        int x = 1,*t;
        float y = 1.50,*u;
        char k = 'c',*v;

        t = &x;
        u = &y;
        v = &k;

        printf("%p %p %p", t, u, v);


        printf("  %p %p %p", t, u, v);

        return 0;

Hi i have made this code but here something unusual is happening , i am printing the addresses , when i increase the address of all then from my view increment in int would be 2 , float would be 4 and char would be 1 but i got the following :

0xbffa6ef8 0xbffa6ef0 0xbffa6eff  0xbffa6efc 0xbffa6ef4 0xbffa6f00

For float and char i think its correct but for int i don't know why it is giving so


You are assuming the sizeof(int) is 2 on your system/envrionment.

However, Your assumption is not correct. The standard does not require the size of int to be 2 or anything specific.

As your program shows the size of int is 4 on your system/envrionment.

Lesson to Learn: Never rely or assume on size of an type, always use sizeof to determine the size, that is the reason the standard provides sizeof.

The memory address increment for t is given by sizeof(int).

If sizeof(int) is different than what you expect t to be incremented by then your assumption is wrong.

An int data type is usually 4 bytes. a short or a short int data type is 2 bytes;

The actual size of integer types varies by implementation. The only guarantee is that the long long is not smaller than long, which is not smaller than int, which is not smaller than short.


sizeof ( short int ) <= sizeof ( int ) <= sizeof ( long int )

But you can be sure that it will be atleast 16 bits in size.

This will be helpful,detailed informations regarding the size of basic C++ types.

Need Your Help

ipython pandas plot does not show

python matplotlib pandas ipython anaconda

I am using the anaconda distribution of ipython/Qt console. I want to plot things inline so I type the following from the ipython console:

Using JQuery to Update Form Fields before passing to PayPal

php jquery mysql ajax

I have spent the day studying up on jquery because I think it will allow me to do this. I have a paypal form and I want the "onClick" button to send this field to my sql table

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.