The age input was successful but compiler doesn’t wait to read name and moves to next statement which was printf("Name is: %s, age is: %d\n",name,age); and the output is "Enter name: Name is: , age is: 23" which we didn’t expect.

Why this happened?

As we enter an integer value and hit enter to read next value, compiler stores either enter or null into the string’s first character and string input terminates.

Here is the proof?

Here we are printing the value of string’s first character by using printf("Name is: %d, age is: %d\n",name[0],age); the output will be "Enter name: Name is: 0, age is: 23"

Here compiler stores, null (0) to the string’s first character that is name[0]

How to fix it?

We have to read a character from input buffer and store it into temporary variable (remember - if we are going to read string or character after an integer or float (in some cases) input then we should read a temporary character which may available in the input buffer)

I am using a statement scanf("%c",&temp); before reading the string (which is going to be read after an integer input).