简体   繁体   中英

C hello world program is crashing on variable output

To start off, I'm coming off from ac# background, so I do have a knowledge on intermediate programming.

So this is my first C program, and when I try to print the variable "testtt" it crashes.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char testtt = "Hello world";
    //scanf("%s", &test);
    printf(testtt);
    return 0;
}

char only holds one character. Use char testtt[] = "Hello world";

Change

char testtt = "Hello world";

to

char testtt[] = "Hello world";

我认为printf也应该是:

printf("%s", testtt);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM