While I was doing cs50 week2.
I found something hard to understand.
#include<stdio.h>
void set_array(int array[4]);
void set_int(int x);
int main(void)
{
int a = 10;
int b[4] = {0, 1, 2, 3};
set_int(a);
set_array(b);
printf("%d %d\n", a, b[0]);
}
void set_array(int array[4])
{
array[0] = 22;
}
void set_int(int x)
{
x = 22;
}
it prints 10, 22. NOT 10, 0.
so I guessed that set_array function may comes first so not 0 but 22.
.
but this one down here, When I tried to play around...
#include<stdio.h>
void set_array(int array[4]);
void set_int(int x);
int main(void)
{
int a = 10;
int b[1];
set_int(a);
set_array(b);
printf("%d %d\n", a, b[0]);
}
void set_array(int array[4])
{
array[0] = 20;
array[1] = 21;
array[2] = 22;
array[3] = 23;
}
void set_int(int x)
{
x = 22;
}
This prints 21 20, NOT 10, 20.
Well if I change it to int b[4];
, it prints 10, 20 as expected.
Is there something wrong on cs50 IDE? or just I don't understand them yet.
Please let me know anything I am missing...