NH MNPXF Imc
NH MNPXF Imc
The output will be the character 'a'. The putchar() function prints a single character to the standard output. The argument 97 is the ASCII
code for the lowercase letter 'a'.
Console Functions: These are older functions like printf(), scanf(), putchar(), getchar(), etc., that interact directly with the console (standard
input/output). They are generally less type-safe and can be less flexible compared to stream functions.
Stream Functions: These are functions that operate on streams of characters. They are part of the iostream library and provide a more
object-oriented approach to input/output. Examples include cin, cout, getline(), <<, >>, etc. Stream functions are generally preferred for their
type safety, flexibility, and better integration with C++ objects.
3. Write a C++ statement to input the string "Computer" using get() function.
C++
char str[10];
cin.get(str, 10);
This code snippet declares a character array str to store the input string.
cin.get(str, 10) reads characters from the standard input stream (cin) and stores them in the str array. The 10 argument specifies the
maximum number of characters to read, including the null terminator.
C++
puts("hello");
puts("friends");
The output will be:
hello
friends
The puts() function prints a string to the console followed by a newline character.
C++
char str[] = "Program";
for (int i = 0; str[i] != '\0'; ++i) {
putchar(str[i]);
}
putchar('-');