+ 2
Is there any memory wastage caused by char a[100][7] in this below code due to garbage value? Or it was rectified by compiler?
In this below code, I use scanf() to get string as a input and store it in a char a[100][7].... Suppose, if I input only limited number of strings... i.e. only four strings eg: ["Chirp", "Rawr", "Grr", "Ssss"] But char a[100][7] can hold "100" string.. We know that unused memory in variable or array,is occupied by garbage values.... Here I input only 4 strings,then there will be 96 unused memory for string in char array.... Is this lead to more memory wastage?[due to unused memory] Or compiler, automatically remove that unused memory in char array, that was occupied by garbage values..... https://code.sololearn.com/cwLdur7XVO7g/?ref=app
7 Respostas
+ 6
Yes it will lead to Memory wastage ....
Inorder to avoid tht u can create the char variable dynamically by using 'new'
+ 3
Yogeshwaran Yes u r right....
Also have a check:
https://www.sololearn.com/Discuss/1825975/?ref=app
+ 3
You don't really need a 2D char array for this, you can reuse the same 1D char array to read input over and over again.
The way you compare input to animal sound isn't quite right. The comparison only considers the first character to compare. It outputs 'Lion' when I pass 'Goal' as input, because the comparison only compares the 'G' letter inside both string.
+ 2
Alphin K Sajan thank you very much ....
It means, compiler doesn't ignore garbage values...And it convert that garbage value to 0's and 1's....
Am I right?
+ 2
Thank you very much Alphin K Sajan đ
+ 2
Ipang thanks for your comments....đ
Before creating this code, I also thought like this only,to compare only using first character of sounds....
But I don't know,how will the hidden test case,will function!đ
So, that only, I think not to take risk.....and to include sound names in my codeđ
even though I included that sound names...
it will compare only first character....[like what you say,on yours comment]
here that is a quit funđ
+ 1
Yogeshwaran Wlcm :)