+ 1
Doubt in this output of this code, please help me to clear this doubt? In C
This code is based on outputting even numbers..... But I don't how does the sizeof(c) comes as zero Without bothering about its real size? Why? For more information please see my code..... https://code.sololearn.com/cF6O97wK1834/?ref=app
4 Answers
+ 1
The main reason is like CarrieForle said. You have initialized c to contain 0 element but your question is "how does it output even numbers....which are to be stored in c[] array by using loop?"
Well, this is a problem in c programming though you have initilized c to contain 0 element it still containing more than 0 element because c is not a high level language like java or c#.In Java and C#, it will raise an exception .Remember, arrays are fixed size, hence always be cautious while accessing arrays. Accessing an element that does not exists is undefined. You may get a valid value or the program may crash.Here you get valid result but it doesn't mean your code is right .This is a bad practice to initialize array.
You should initialize the array int c[a]; not c[e].
+ 2
Because e is 0, making c[0]. c contains no element and can't contain any; thus 0.
+ 2
+ 1
CarrieForle Then how does it output even numbers....which are to be stored in c[] array by using loop?
and please also see that I keep on changing "e" value in for loop...
e is not equal to zero ..