What is the usage of the cin function in C language?
In C language, there is no cin function, which is the standard input stream object used for receiving user input in C++. In C language, you can use the scanf() function to receive user input.
The usage of the scanf() function is as follows:
#include <stdio.h>
int main() {
int num;
printf("请输入一个整数: ");
scanf("%d", &num);
printf("您输入的整数是: %d", num);
return 0;
}
In the code above, the statement scanf(“%d”, &num); is used to receive an integer input from the user and store it in the variable num. %d is the format specifier that indicates it’s an integer input. &num represents the address of the variable num, and scanf() function stores the user’s input value in the variable through this address.
It is important to note that the format specifiers in the scanf() function’s formatting string should match the type of variables to ensure correct input and storage.