Hi,
I have a doubt about passing values to a function accepting string.
=============== =============== ========
#include <iostream>
using namespace std;
int main()
{
void print(const string&);
print("hi");
print(NULL);
return 0;
}
void print(const string& s)
{
cout<<"s is "<<s<<endl;
}
=============== =============== ========
The above program compiles successfully but fails at run time because
NULL is passed as argument in the second call to print.
Why doesn't the compiler give an error on passing of NULL value?
How could we check for such arguments in our program when we are using
strings?
Regards
Sanjay Raghani
I have a doubt about passing values to a function accepting string.
=============== =============== ========
#include <iostream>
using namespace std;
int main()
{
void print(const string&);
print("hi");
print(NULL);
return 0;
}
void print(const string& s)
{
cout<<"s is "<<s<<endl;
}
=============== =============== ========
The above program compiles successfully but fails at run time because
NULL is passed as argument in the second call to print.
Why doesn't the compiler give an error on passing of NULL value?
How could we check for such arguments in our program when we are using
strings?
Regards
Sanjay Raghani
Comment