Hello, suppose I have a 2d array
a [9] [3] = { 0 } ;
and letβs say I want to print its 3rd row then if I write
cout<<a[2] <<endl;
will it print my 3rd row ?
Hello, suppose I have a 2d array
a [9] [3] = { 0 } ;
and letβs say I want to print its 3rd row then if I write
cout<<a[2] <<endl;
will it print my 3rd row ?
Hey @yashsharma4304
No it wont ,instead it will print the starting address of that row
When you do *a[2] it will print element at a[2][0]
Hey @yashsharma4304
Things are different in char arrays
It will start printing from that location and keeps printing until they find a NULL, if u remove β\0β after a,b and then print a[0] it will print a,b,(garbage char),d,e,f
Ok so in this code what I am getting in the output? Is it a garbage value or something else
Bro you are using integer arrays in above code so
Ok so 0x7ffd8f6dd260 is representing the address of the first block of that array ?
Yes
β¦
I have removed the null character in my code but why is it not printing garbage value ? Instead of printing garbage value it is printing the value inside next row.
because there are 4 columns and all are filled,
Do this in same program : char b[3][10] = {{βcβ,βdβ,βeβ,βfβ}, {βyβ,β\0β},{βdβ,βeβ,β\0β}}; make cols 10
Sometimes garbage can also contain β\0β chars
Sometimes garbage can also contain β\0β chars
Ok.