+ 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

5th Dec 2020, 3:21 PM
Yogeshwaran P
Yogeshwaran P - avatar
5 Antworten
+ 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].
5th Dec 2020, 5:22 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
Because e is 0, making c[0]. c contains no element and can't contain any; thus 0.
5th Dec 2020, 3:24 PM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 2
Thank you CarrieForle ,Zatch bell ,C-MOON for clearing my doubt...☺️
6th Dec 2020, 1:45 AM
Yogeshwaran P
Yogeshwaran P - avatar
+ 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 ..
5th Dec 2020, 3:40 PM
Yogeshwaran P
Yogeshwaran P - avatar