ExamVeda
Login
Home
1
What is the primary purpose of a function prototype in C?
Discuss
Answer & Solution
Answer: Option B
Solution:
The primary purpose of a function prototype in C is to declare a function. It serves as a forward declaration of the function, providing information about the function's name, return type, and the types of its parameters. This declaration allows the compiler to understand how the function should be called and used in the program before the actual function definition is encountered.

So, the correct answer is:
Option B: Declare a function

In C, a function prototype typically looks like this:

return_type function_name(parameter_type1, parameter_type2, ...);

Here's an example:
int add(int a, int b);

This prototype informs the compiler that there's a function named "add" that returns an integer and takes two integer parameters. It doesn't define the function's implementation; it simply declares its existence and signature.
2
Which character is used to indicate the end of a statement in C?
Discuss
Answer & Solution
Answer: Option B
Solution:
The character used to indicate the end of a statement in C is ;. This semicolon is a crucial part of C syntax as it separates statements and tells the compiler where one statement ends and the next one begins.

So, the correct answer is:

Option B: ;

In C programming, you terminate a statement with a semicolon. For example:

#include <stdio.h>
int main() {
  int x = 5;
  printf("Hello, World!");
  return 0;
}


In the above code, the semicolon at the end of each line signifies the end of the respective statement.
3
Which data type is used to represent a single character in C?
Discuss
Answer & Solution
Answer: Option A
Solution:
The data type used to represent a single character in C is char. The char data type is specifically designed to store individual characters, such as letters, digits, and symbols.

So, the correct answer is:
Option A: char

In C programming, you declare a character variable like this:

char myChar = 'A';

Here, myChar is a variable of type char, and it stores the character 'A'. The char data type is essential for working with characters and strings in C.
4
What is the correct syntax for declaring a variable in C?
Discuss
Answer & Solution
Answer: Option A
Solution:
The correct syntax for declaring a variable in C is Option A: int variable_name;. In C, you declare a variable by specifying its data type followed by the variable name and a semicolon to terminate the declaration.

So, the correct answer is:
Option A: int variable_name;

Here's an example:

int age;

In this example, we declare an integer variable named "age." This syntax informs the compiler that "age" is of type int. Option B is incorrect because it's an assignment statement, not a declaration. Option C and Option D have incorrect syntax and are not valid ways to declare a variable in C.
5
Which symbol is used for the 'modulo' operation in C?
Discuss
Answer & Solution
Answer: Option A
Solution:
The symbol used for the 'modulo' operation in C is %. The '%' symbol calculates the remainder when one number is divided by another and is commonly used for tasks such as checking for even or odd numbers and cycling through a range of values.

So, the correct answer is:
Option A: %

Here's an example of using the modulo operator in C:

int remainder = 10 % 3;

In this example, the value of 'remainder' will be 1 because 10 divided by 3 is 3 with a remainder of 1.
6
What is the default return type of a function in C if not specified?
Discuss
Answer & Solution
Answer: Option A
Solution:
The default return type of a function in C if not specified is Option A: int. In C, if you don't explicitly specify the return type of a function, it is assumed to return an integer (int) by default.

So, the correct answer is:
Option A: int

For example, if you have a function like this:

myFunction() {
// Function code
}

The return type is assumed to be int, and you can call it as if it returns an integer. If you want a function to return nothing, you explicitly specify Option B: void as the return type.
7
Which operator is used for 'logical AND' in C?
Discuss
Answer & Solution
Answer: Option A
Solution:
The operator used for 'logical AND' in C is Option A: &&. The && operator is used to perform a logical AND operation, which returns true if both of its operands are true, and false otherwise.

So, the correct answer is:
Option A: &&

Here's an example of using the logical AND operator in C:

if (x && y) {
// Code to be executed if both x and y are true
}

In this example, the code within the if statement will be executed only if both 'x' and 'y' are true.
8
What is the purpose of the 'sizeof' operator in C?
Discuss
Answer & Solution
Answer: Option B
Solution:
The purpose of the 'sizeof' operator in C is to determine the size of a data type or a variable in bytes. It is used to find out how much memory is allocated to a specific data type or an object in memory.

So, the correct answer is:
Option B: Determine size

Here's an example of how 'sizeof' operator is used in C:

int size = sizeof(int);
printf("Size of int: %d\n", size);

In this example, 'sizeof(int)' will return the size (in bytes) of the 'int' data type, and it will be stored in the 'size' variable. It is a valuable operator when you need to work with memory allocation and management in C.
9
In C, which type of variable should be used to store decimal numbers?
Discuss
Answer & Solution
Answer: Option C
Solution:
In C, you can indeed use the float data type to store decimal numbers. However, it's important to note that float is typically used for single-precision floating-point numbers, which have a lower precision and a more limited range compared to double.

So, to clarify:

If you require high precision and a wide range for storing decimal numbers, Option D: double is the more common choice.

Option C: float is a valid choice when you can tolerate slightly lower precision and a somewhat limited range, or when memory constraints are a concern, as float typically requires less memory than double.

In summary, both float and double can be used to store decimal numbers, but the choice between them depends on your specific requirements for precision and range.
10
Which header file should be included for input and output functions in C?
Discuss
Answer & Solution
Answer: Option B
Solution:
The header file that should be included for input and output functions in C is Option B: <stdio.h>. The <stdio.h> header file provides declarations for functions like printf, scanf, getchar, and many others that are used for input and output operations in C.

So, the correct answer is:

Option B: <stdio.h>

Including this header file at the beginning of your C program allows you to use standard input and output functions to interact with the user and manipulate data.