#include <stdio.h>
#include <string.h>
int main(void) {
char *w;
strcpy(w, "Hello Word");
printf("%s\n", w);
return 0;
}
What is wrong with the way the char pointer is used in the above code?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Ok, you did not ask to the system for memory, to use it with the string. This code will work
That code declare w as an array of char, reserving the memory space for it. Other alternative is to use malloc or calloc for the char pointer. Read about that.