Q: 1 To calculate the square root of given value we use __________ predefined function in C language.
The sqrt() function
The root() function
The square() function
The math() function
[ Option A ]
In C programming, when we want to calculate the square root of a number, we use a predefined function called sqrt(). This function is available in the math.h header file, so we must include it at the beginning of the program using #include<math.h>.
#include <stdio.h>
#include <math.h>
int main()
{
float num, result;
printf("Enter a Number: ");
scanf("%f", &num);
result = sqrt(num);
printf("Square Root of %f is %f",num,result);
return 0;
}
Q: 2 Identify the format specifier used to print a number in octal representation.
%c
%io
%o
%0i
[ Option C ]
In C language, different format specifiers are used to print numbers in various number systems.
The octal representation of a number is printed using the %o format specifier. For hexadecimal output, C provides two specifiers, %x for lowercase letters (a–f) and %X for uppercase letters (A–F). For decimal output %d or %i is used.
Q: 3 The function scanf() returns?
1
0
ASCII value of last input
The number of successful read input values
[ Option D ]
The scanf() is a formatted input function used to take input from the user. Besides reading input, scanf() also returns a value.
The return value of scanf() is the number of input values that are successfully read and assigned to the given variables.
Q: 4 Which of the following is formatted function?
printf()
scanf()
Both (a) and (b)
None of these
[ Option C ]
Both printf() and scanf() are formatted input-output functions in C. The printf() function is used to display output on the screen using format specifiers while scanf() is used to read input from the user in a formatted manner using the format specifiers.
| FORMAT SPECIFIER | DATA TYPE |
|---|---|
| %c | For character type. |
| %s | For string. |
| %d | For signed integer. |
| %i | For signed integer. |
| %u | For unsigned integer. |
| %ld | For signed long integer. |
| %lu | For unsigned long integer. |
| %lld | For long long integer. |
| %p | For pointer (memory address). |
| %o | For octal number. |
| %x | For hexadecimal number. |
| %f | For float type. |
| %lf | For double type. |
| %% | For prints a percent sign. |
Q: 5 How many main() functions can be defined in a C program?
2
1
3
Any number of times
[ Option B ]
In C, the execution of program begins from main() function. Therefore, a C program can have only one main() function. Defining more than one main() function will cause a compilation error because the compiler will not know where to start executing the program.
Q: 6 The statement
char a=‘a’;
printf(“%d”,a);
Will print?
Compilation error
97
65
92
[ Option B ]
The character 'a' is stored in the variable a. When we print it using %d, C prints its ASCII value. The ASCII value of 'a' is 97.
Q: 7 What is value of r, after executing the following code?
void main()
{
int a=10,b=20,r;
r=printf("%d %d",a,b);
printf("%d",r);
}
4
5
1
2
[ Option B ]
The printf() is not only used to display output, it also returns a value. The return value of printf() is the total number of characters printed on the screen.
The statement printf("%d %d", a, b); prints the value of a, then a newline, and then the value of b.
So, the total number of characters printed is 5.
This value 5 is returned by printf() and stored in the variable r. Then printf("%d", r); prints the value of r, which is 5.
Q: 8 The unformatted input/output function in C language can work with?
All type of values
Character type value
Integer type value
Either (b) or (c)
[ Option B ]
Unformatted I/O functions do not use format specifiers and mainly work with single characters or strings. Example included getchar(), putchar(), gets(), puts(). These functions are simple and are mostly used for character-based input and output.
| FUNCTION | USED FOR | SYNTAX |
|---|---|---|
| getchar() | Reads a single character from keyboard. | ch=getchar(); |
| putchar() | Prints a single character on screen. | putchar(ch); |
| gets() | Reads a string. | gets(str); |
| puts() | Prints a string and moves to next line. | puts(str); |
Although gets() is unsafe because it does not check the size of input, which may cause buffer overflow and removed in modern C. The fgets() is used instead of gets() because it is safe and size-bounded.
Syntax:
fgets(string_name,size,stdin);
E.g.:
char name[50];
printf("Enter Name: ");
fgets(name,sizeof(name),stdin);
Q: 9 Which of the following is example(s) of unformatted function in C language?
clrscr()
sqrt()
getchar()
sleep()
[ Option C ]
In C language, unformatted input/output functions are those functions that do not use format specifiers like %c, %d, %f, etc. and are mainly used for simple input or output, especially characters or strings. Commonly used unformatted I/O functions are getchar(), putchar(), gets(), puts().
Q: 10 Which of the following functions provide the conversion symbol to identify the data type?
Unformatted
Library
User defined
Formatted
[ Option D ]
In C language, formatted input/output functions such as printf() and scanf() use conversion symbols (format specifiers) to identify the data type of the value being printed or read.
For example, the format specifier %d for integers, %f for floating-point values, %c for characters, and %s for strings.
| FORMAT SPECIFIER | DATA TYPE |
|---|---|
| %c | For character type. |
| %s | For string. |
| %d | For signed integer. |
| %i | For signed integer. |
| %u | For unsigned integer. |
| %ld | For signed long integer. |
| %lu | For unsigned long integer. |
| %lld | For long long integer. |
| %p | For pointer (memory address). |
| %o | For octal number. |
| %x | For hexadecimal number. |
| %f | For float type. |
| %lf | For double type. |
| %% | For prints a percent sign. |
Q: 11 What value prints the below program
void main()
{
int a=65,b=065;
printf("%d %c",a,b);
}
65 65
65 5
65 53
65 6
[ Option B ]
In this program, the value of a is simply 65, which is a decimal number. But the value of b is written as 065, and in C, any number that begins with a leading zero is treated as an octal number.
The octal number 065 is converted to decimal as 53. When printing, %d displays the integer value 65, while %c prints the character that corresponds to ASCII value 53, which is the character '5'. Therefore, the output of the program becomes 65 5.
Q: 12 What is value of r, after executing the following code?
void main()
{
int a,b,r;
r=scanf("%d%d",&a,&b);
printf("%d",r);
}
Compile time error
Run time error
2
0
[ Option C ]
The scanf() is a formatted input function. The scanf() reads formatted input and returns the number of input values successfully read and assigned.
In the given code, scanf("%d%d", &a, &b); is used to read two integer values from the user, and when the user enters both integers correctly, scanf() successfully assigns the values to a and b.
In such a case, scanf() returns the number of inputs successfully read, which is 2. This return value is stored in the variable r, and finally printf("%d", r); prints the value of r, which is 2.
Q: 13 The prototype of exit() function is defined in __________ header file.
process.h
stdio.h
math.h
Both (a) and (b)
[ Option A ]
The exit() function in C is used to terminate a program immediately. Its official and standard prototype is actually defined in stdlib.h.
However, the header file process.h where Turbo C/C++ provides the prototype of exit() as well.
Q: 14 What value will print after executing the below program
void main()
{
int a,b;
a=65*66;
b='A'*'B';
printf("%d %d ",a,b);
}
4290 AB
4290 4290
4290 0
None of these
[ Option B ]
In C language, characters are internally stored as integer values using their ASCII codes. Whenever arithmetic operations are performed on characters, their ASCII values are used automatically.
Here the variable a is assigned the value 65*66, which results in 4290. For the variable b, the characters 'A' and 'B' are used in an arithmetic operation. As we know, characters are internally represented by their ASCII values, where 'A' has an ASCII value of 65 and 'B' has an ASCII value of 66. Therefore, the expression 'A'*'B' is actually evaluated as 65*66, which also gives 4290.
Since the printf() statement uses the %d format specifier, both values are printed as integers.
Q: 15 What value would be after executing the below code
void main()
{
char character;
int integer;
character='a';
integer=character-'A';
printf("%d",integer);
}
-32
32
0
Compile time error occurred
[ Option B ]
In this program, the character 'a' is assigned to the variable character. In C, characters are stored as their ASCII values, where 'a' corresponds to 97 and 'A' corresponds to 65. The program then calculates integer=character-'A', which means 97–65, resulting in 32.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.