D
D
dandropov952018-09-15 11:52:03
C++ / C#
dandropov95, 2018-09-15 11:52:03

Why doesn't the two-line output program work?

Please tell me why this program does not work. In MSVC the error takes off. Runs in GCC but doesn't output.

#include <stdio.h>

int main(void)
{
  typedef char * string;

  string first_name;
  string last_name;

  scanf("%s %s", first_name, last_name);
  printf("%s %s", last_name, first_name);

  return 0;
}

// А так работает 
char first_name[40];
char last_name[40];

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2018-09-15
@dandropov95

in simple terms:

typedef char * string; 
string first_name; - это просто указатель, причем неинициализированный.

scanf("%s %s", first_name, last_name); - это обращение 
к неинициализированному указателю (undefined behaviour)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question