q1)Can I know what is happening inside this code that is making it not able to display garbage at the end of the first loop but simply move to the next line
and display the sizeof(mx)
q2)c is not very good at keeping track of how long arrays are,does the same apply for c++ or is it compiler specific?
I was playing with it and something is messed up with your "printf" command it was messing up some of my code I put into it. Also it didn't look like sizeof() was working right ether but I could be wrong.. and I'm sure I wasn't using it right. I've never learned them functions..
my C++ code..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <string>
//using namespace std;
int main()
{
std::string name = "MATTHEW";
for (int i = 0; i != name.size(); ++i)
{
std::cout << name[i] << std::endl;
}
std::cout << "Size of string is: " << name.size() << std::endl;
//system("PAUSE");
return 0;
}
sizeof(mx) has nothing to do with my questions ,as it will always print 8 in case of a 64bit machine and 4 in case of a 32 bit machine .
printf is c language equivalent of cout.
Here is the kindof pure c++ code but my questions remain the same ..