rongz
asked on
Declare a variable without initialization
Hello,
after declaration of char str[1024]; (without intialization or assignment), what value the str points to? Does char str[1024]; equal to char str[1024]="";? Thanks.
after declaration of char str[1024]; (without intialization or assignment), what value the str points to? Does char str[1024]; equal to char str[1024]="";? Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Memory has a lot of zeros in it. You got lucky.
This typically works too, but you shouldn't depend on it:
--------8<--------
#include <stdio.h>
void foo();
void foo2();
int main()
{
foo();
foo2();
}
void foo()
{
char buf[256];
strcpy(buf,"Hello, World\n");
}
void foo2()
{
char buf[256];
printf(buf);
}
--------8<--------
--------8<--------
#include <stdio.h>
void foo();
void foo2();
int main()
{
foo();
foo2();
}
void foo()
{
char buf[256];
strcpy(buf,"Hello, World\n");
}
void foo2()
{
char buf[256];
printf(buf);
}
--------8<--------
ASKER
--------------------------
#include <string.h>
#include <stdio.h>
void main(int argc, char **argv){
char max[124];
if (strcmp(max, "")==0)
printf("hit\n");
else
printf("not hit\n");
}