Quick actions

cmd+k|ctrl+k

Navigation

Languages

scanf v.s. assign string directively

Snippet info

Language

C

Visibility

public

Author

homex

Created

2022-10-10T18:45:52.439219Z

Updated

2022-10-10T18:46:38.784296Z

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

int main(void)
{
    char *s = "Hi!";
    char *t = "Hi!";

    char *x = malloc(5);
    char *y = malloc(5);

    printf("x: ");
    scanf("%s", x);
    
    printf("y: ");
    scanf("%s", y);

    if (s == t)
    {
        puts("s, t: Same");
    }
    else
    {
        puts("s, t: Different");
    }

    if (x == y)
    {
        puts("x, y: Same");
    }
    else
    {
        puts("x, y: Different");
    }
   
}
INFO