Going through The C Programming Language book right now and got confused about the "Arrays" section, so I came here. I am super glad I found this explanation, thank you!!
I am not sure if you cover it but you can also use sizeof to determine the length of the array. Instead of setting a variable size to a hard coded value. You can do: #include #include int main() { int arr[5] = {1,2,3,4,5}; for (int i = 0; i < sizeof(arr)/sizeof(int); i++) { printf(" %d", arr[i]); } return EXIT_SUCCESS; } What is your thought on using sizeof() to determine the length of arrays. I have read articles of conflicting opinions. Some say you shouldnt use sizeof(), others say use it.
You can read the array as well: for(i = 0; i < size; i++) { printf("Array element %d: ", i); scanf("%d", &array[i]); } for(i = 0; i < size; i++) { printf("%d ", array[i]); }
instead of having the size statically defined can you have it defined by user input: ??? scanf("%d", &size); arr[size]; (I tried this but returns seg fault 11)
so I tried it but when I plugged the variable in here int size = 5; int myGrades[size]; it says that it cannot have size as its array size and must be a constant value help?
TRYHARD Gamer declare it as const int size = 5; Sizes are not supposed to chance, so you have yo change it to a constant value that way or with #define SIZE 5 right below your libraries
Line13 has a major flaw in it and the "for" statement never gets past " i++ ". I changed it to a "while" statement and put the " i ++ " below the "printf " and it works fine.
According to Calebs c++ course, arrays don't know there own size. but there's a workaround for it: the "sizeof" function. it returns sizeof something bytewise. so to get the actual size of an array you need to divide sizeof(array) by sizeof(one element of that array). in code it would look smth like: int array[n]; int size = sizeof(array) / sizeof(array[0]); // = n
I love your sense of humour. I don't just appreciate how you make programming so easy, but I also appreciate your personality (:
Authenticity matters
Going through The C Programming Language book right now and got confused about the "Arrays" section, so I came here. I am super glad I found this explanation, thank you!!
I am not sure if you cover it but you can also use sizeof to determine the length of the array.
Instead of setting a variable size to a hard coded value. You can do:
#include
#include
int main() {
int arr[5] = {1,2,3,4,5};
for (int i = 0; i < sizeof(arr)/sizeof(int); i++) {
printf("
%d", arr[i]);
}
return EXIT_SUCCESS;
}
What is your thought on using sizeof() to determine the length of arrays. I have read articles of conflicting opinions. Some say you shouldnt use sizeof(), others say use it.
whatever works, works
I am so happy that I am still watching this. Thanks for your work! It's simple for us to look and listen! Thanks
I dont often judge people, but you are a hell of a nice guy
#include
int main(void)
{
int size = 3;
int array[size];
int i = 0;
array[0] = 88;
array[1] = 77;
array[2] = 55;
while(i < size)
{
printf("%d ", array[i++]);
}
return 0;
}
#WhileIsClean
You can read the array as well:
for(i = 0; i < size; i++)
{
printf("Array element %d: ", i);
scanf("%d", &array[i]);
}
for(i = 0; i < size; i++)
{
printf("%d ", array[i]);
}
The dog is the real antagonist here.
5:48 What did your dog want?
You're amazing buddy, many thanks
instead of having the size statically defined can you have it defined by user input: ???
scanf("%d", &size);
arr[size];
(I tried this but returns seg fault 11)
int a;
scanf("%d", &a);
int array[a];
here it works, if you paste the code we can help '-'
is it possible?? i mean you have to put the content in the arrays too man
@@surjeetsingh3603 you could have user input "a" number of values
Printing array is a array printer it changes thing in box u have to put in a
Box your collection if was DVD watever
i love this fam! this is good stuff.
I have a question.If the array is myGrades and the size is 5.What happens when we didn't put myGrades[2]
Followed this perfectly and carefully reviewed it and it still returns nothing when I compile. CS is hell.
why does: int myGrades[size];
word size has a red squiggly line under it? everything is correct based off your code.
im using microsoft VS
@2:55 My man said "all [uhh] all we have to do is.."
Thank u!!! I love your personality too :D
I tested and myGrades[ ] is 0 based.
so I tried it but when I plugged the variable in here
int size = 5;
int myGrades[size];
it says that it cannot have size as its array size and must be a constant value
help?
TRYHARD Gamer declare it as const int size = 5;
Sizes are not supposed to chance, so you have yo change it to a constant value that way or with #define SIZE 5 right below your libraries
@@chrisgmag22 if you #define size 5, you have to delete the int size = 5;
God, intro to C is so annoying
Line13 has a major flaw in it and the "for" statement never gets past " i++ ". I changed it to a "while" statement and put the " i ++ " below the "printf " and it works fine.
Thank you!
Is there something similar to array.length for C?
According to Calebs c++ course, arrays don't know there own size. but there's a workaround for it: the "sizeof" function. it returns sizeof something bytewise. so to get the actual size of an array you need to divide sizeof(array) by sizeof(one element of that array). in code it would look smth like:
int array[n];
int size = sizeof(array) / sizeof(array[0]); // = n
go for loops whoo! lol
Thank you so much
The best!
Hello. What compiler do you use?
GCC
whats the song at the end?
Tropical Summer by ARTISS.
www.jamendo.com/track/1452505/tropical-summer?language=en
Nice
ni yabba
You are declaring a int at line 13 which isn't allowed in C.
It's okay to declare a variable in a for loop. It just cannot be used outside of the loop.
Thank you so much