[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

int foo[5]; What is the type of foo? You should know this.

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 29
Thread images: 4

File: 1493108585612.png (638KB, 4760x4986px) Image search: [Google]
1493108585612.png
638KB, 4760x4986px
int foo[5];


What is the type of foo? You should know this.
>>
foo is a pointer to an int array of size 5.
>>
>>60086901
in C
>>
File: 1481085470700.jpg (264KB, 1280x853px) Image search: [Google]
1481085470700.jpg
264KB, 1280x853px
>>60086901

>foo is a pointer
Whoops! Would you like to try again?
>>
>>60086993
*foo is equivalent to foo[0]
*(foo + 4) is equivalent to foo[4]

so yes, it's a pointer.
>>
>>60086855
"array of 5 integers"
What is the point of this thread?

>>60087041
arrays are convertibles to pointers through a standard conversion but aren't pointers.
>>
>>60087063
>Can be dereferenced like pointers

FTFY
>>
>>60086993
foo is an array of 5 ints.

So, of course, &foo is a pointer to an array of 5 ints.

Try running
printf("%p %p %p %p", foo, foo + 1, &foo, &foo + 1);
>>
>>60087109
int foo[5];
foo[0] = 2;
printf("%d %p %p", *foo, foo, &foo);

2 0x7ffecdb99b00 0x7ffecdb99b00
>>
>>60087106

>I don't know what decay is
>>
>>60086855
The type is "array of 5 int".
>>
fcking retards
foo is pointer, array is only imaginary word
foo points to address based on [x] as foo + type * x
>>
>>60087109
&foo is a reference
*fpointer = &foo is a pointer
>>
>>60087235
>array is only imaginary word
wow, it's not even a real word? Look at that!
>>
its type is
>sub esp, 5*sizeof(int)
>>
>>60087250
Arrays are automatically passed as a ref went sent as a parameter to functions..
>>
>>60087161
And what about
foo + 1
and
&foo + 1
? In this example they should end in 9b04 and 9b14 respectively.
>>
>>60087293
Foo+1 4 bytes
Foo+2 10 bytes
M'kay
>>
>>60087235

Use sizeof senpai, you'll be surprised
>>
File: images (62).jpg (24KB, 492x299px) Image search: [Google]
images (62).jpg
24KB, 492x299px
Use vectors
>>
>>60086855
Stop using C.
>>
>>60087329
    printf("sizeof(int):    %d\n", sizeof(int));
printf("sizeof(int*): %d\n", sizeof(int *));
printf("sizeof(int **): %d\n", sizeof(int **));

int foo[5];
foo[0] = 2;
printf("%d %p %p %p %p\n", *foo, foo, &foo, foo+1, &foo+1);

2 0x7ffc80a982c0 0x7ffc80a982c0 0x7ffc80a982c4 0x7ffc80a982d4
>>
>>60087442
fuck forgot the rest
sizeof(int):    4                                                                                                                                                                                               
sizeof(int*): 8
sizeof(int **): 8
>>
>>60087456
I don't you did that correct
>>
Wouldn't it make sense that a pointer is 64 bits on a 64bit arch? Int is only guaranteed to be between char and long
>>
File: livewithpurpose.gif (47KB, 306x469px) Image search: [Google]
livewithpurpose.gif
47KB, 306x469px
>>60086855
>this thread
you really need to find more interesting things to argue about
>>
Arrays and pointers are actually slightly different in C. In C an array also has information about the number of elements if it was allocated on the stack. This allows you to use sizeof(array)/sizeof(array[0]) to get the number of elements in the array. This only works on arrays and not pointers as the size of a pointer is just whatever size your machine uses (32 or 64 bits).
>>
>>60086855
I know it's type is int[5], but only because I saw some of the retarded sycophants on #C on freenode pitch a fit about it once to satisfy one of that channel's admins.
>>
>>60089101
*its
fucked that up, was originally going to type "it's int[5]"...
Thread posts: 29
Thread images: 4


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.