0% found this document useful (0 votes)
7 views4 pages

NH MNPXF Imc

Uploaded by

kuttukuttan126
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

NH MNPXF Imc

Uploaded by

kuttukuttan126
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Very Short Answer Type

1. What will be the output of the statement: putchar(97); be?

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'.

2. Distinguish between console functions and stream functions.

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.

4. Write down the output of the following code segment:

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.

Short Answer Type

1. Predict the output of the following code segment:

C++
char str[] = "Program";
for (int i = 0; str[i] != '\0'; ++i) {
putchar(str[i]);
}
putchar('-');

You might also like