How do you declare cin in the C language?
There is no keyword “Cin” in the C language; it is an input stream object used in C++ to read data from the standard input stream. In C, you can achieve similar functionality using the standard library function scanf.
The usage of the scanf function is as follows:
#include <stdio.h>
int main() {
int num;
printf("请输入一个整数:");
scanf("%d", &num);
printf("您输入的整数是:%d\n", num);
return 0;
}
In the above code, “%d” is the format control string used to specify that the input data type is an integer. “&num” is the address of the variable num, used to store the input integer in the num variable.
It is important to note that when using the scanf function, one must ensure that the input data type matches the data type specified in the format control string, otherwise it may lead to errors or undefined behavior. Additionally, the scanf function ignores spaces and newlines when reading input until it encounters a character that does not match the format control string.