C Language Fundamentals
All Questions for: C Language Fundamentals
Question 1: What will be the output of the following C code?
- A 2
- B Compile time error
- C -1
Explanation: This question tests your understanding of bitwise operators in C. Let's break down the code step by step. The tilde (~) is the bitwise NOT operator. It flips all the bits of the variable `x`. Since `x` is 0 (which is represented as all 0s in binary), `~x` will become -1 (represented as all 1s in two's complement). The ampersand (&) is the bitwise AND operator. It compares the corresponding bits of two operands. If both bits are 1, the resulting bit is 1; otherwise, it's 0. We're performing a bitwise AND between `~x` (-1, all 1s) and `y` (2). Let's assume your system uses 32-bit integers (most do). Then 2 is represented as `00000000000000000000000000000010` in binary. The bitwise AND operation will be: This results in 2. This line prints the value of `z`, which is 2, to the console. The exact binary representation and the behavior of bitwise NOT might depend slightly on your specific compiler and system architecture, but the principle remains the same.
Question 2: What is the purpose of the 'sizeof' operator in C?
- A Calculate square root
- B Perform division
- C Convert to string
- D Determine size
Explanation: The purpose of the 'sizeof' operator in C is to 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: Here's an example of how 'sizeof' operator is used in C: 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.
Question 3: Which of the following are unary operators?
- A -
- B sizeof
- C ++
- D all of the mentioned
Explanation: No explanation is given for this question
Question 4: What will be the output of the following C function?
- A Undefined behaviour
- B Segmentation fault
- C Compilation error
- D 1 2 3 4 5
Explanation: No explanation is given for this question
Question 5: What will be the final values of a and c in the following C statement? (Initial values: a = 2, c = 1)
- A a = 0, c = 0;
- B a = 2, c = 1;
- C a = 1, c = 2;
- D a = 2, c = 2;
Explanation: a = 2, c = 1; The statement is: This is a . The condition is , which means if , the expression before the colon is executed. Since (non-zero), the true part is executed: Then the value of the true expression () is assigned to . So now: (since the result of is 0)
Question 6: Which operator is used for 'logical AND' in C?
- A &&
- B ||
- C |
- D &
Explanation: The operator used for 'logical AND' in C is . 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: Here's an example of using the logical AND operator in C: In this example, the code within the if statement will be executed only if both 'x' and 'y' are true.
Question 7: Pick the incorrect statement with respect to enums.
- A It is not possible to change the value of enum symbols
- B Enum variables are automatically assigned values if no value is specified
- C Only integer constants are allowed in enums
- D Two enum symbols cannot have the same value
Explanation: No explanation is given for this question
Question 8: Which character is used to represent a comment in C code?
- A ;
- B //
- C /*
- D #
Explanation: The character used to represent a comment in C code is . In C, the double forward slash () is used to begin a single-line comment. Comments are used for adding explanations or notes within the code that are ignored by the compiler and are solely for human readability. So, the correct answer is: Here's an example of a single-line comment in C:
Question 9: What does the 'NULL' keyword represent in C?
- A A pointer to nothing
- B An uninitialized variable
- C An empty string
- D A null character
Explanation: No explanation is given for this question
Question 10: Will the following C code compile without any error?
- A Error
- B Yes
- C No
- D Depends on the C standard implemented by compilers
Explanation: No explanation is given for this question
Question 11: What is the size of myArray in the code shown below? (Assume that 1 character occupies 1 byte)
- A 5 bytes
- B 50 bytes
- C 10 bytes
- D 40 bytes
Explanation: No explanation is given for this question
Question 12: Which data type is used to store a sequence of characters in C?
- A float
- B string
- C int
- D char
Explanation: The data type used to store a sequence of characters in C is . In C, you can use an array of characters (often referred to as a "string") or simply a single character variable to store individual characters or sequences of characters. So, the correct answer is: In C, you can declare a character array (string) like this: In this example, 'myString' is an array of characters, and it can store a sequence of characters, including letters, digits, symbols, and spaces.
Question 13: Variable name resolution (number of significant characters for the uniqueness of variable) depends on . . . . . . . .
- A C language
- B Compiler and linker implementations
- C None of the mentioned
- D Assemblers and loaders implementations
Explanation: No explanation is given for this question
Question 14: Which of the following is not a valid C keyword?
- A printf
- B for
- C main
- D if
Explanation: Among the options provided, is not a valid C keyword. C keywords are reserved words that have special meanings in the language, and they cannot be used as identifiers (such as variable names or function names). Keywords like 'main,' 'if,' and 'for' are all valid C keywords with specific purposes in the language. However, 'printf' is not a keyword; it's a standard C library function used for outputting formatted text. It can be used as a function name in C code. So, the correct answer is:
Question 15: Assuming a short is two bytes long, what will be printed by the above code?
- A 6
- B 12
- C 7
- D 24
Explanation: The following table provides the details of standard integer types with their storage sizes and value ranges ?
Question 16: What is the difference between a declaration and a definition of a variable?
- A A declaration occurs once, but a definition may occur many times.
- B Both can occur multiple times, but a declaration must occur first.
- C Both can occur multiple times, but a definition must occur first.
- D A definition occurs once, but a declaration may occur many times.
Explanation: No explanation is given for this question
Question 17: Which operator is used to access the value stored at a pointer address in C?
- A .
- B ->
- C *
- D &
Explanation: No explanation is given for this question
Question 18: What is the purpose of the 'goto' statement in C?
- A End the program
- B Skip the current iteration
- C Transfer control
- D Skip a loop
Explanation: No explanation is given for this question
Question 19: We want to declare x, y and z as pointers of type int. The alias name given is: intpt The correct way to do this using the keyword typedef is:
- A typedef int* intptr; intptr x,y,z;
- B int typedef* intptr; int x,y,z;
- C typedef* intptr; int x,y,z;
- D int typedef* intptr; intptr x,y,z;
Explanation: No explanation is given for this question
Question 20: Which of following is not a valid name for a C variable?
- A Exam_veda
- B Both A and B
- C Examveda
- D Exam veda
Explanation: No spaces are allowed in the variable names.
Question 21: What is the primary purpose of a function prototype in C?
- A Declare a variable
- B Define a function
- C Declare a function
- D Assign a value
Explanation: The primary purpose of a function prototype in C is to . 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: In C, a function prototype typically looks like this: Here's an example: 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.
Question 22: What does the 'void' keyword indicate in a C function declaration?
- A Floating-point return
- B Empty return type
- C Integer return
- D String return
Explanation: The 'void' keyword in a C function declaration indicates . When a function is declared with 'void' as its return type, it means that the function does not return any value.
Question 23: Which data type is used to represent a single character in C?
- A float
- B int
- C char
- D double
Explanation: The data type used to represent a single character in C is . The data type is specifically designed to store individual characters, such as letters, digits, and symbols. So, the correct answer is: In C programming, you declare a character variable like this: Here, is a variable of type , and it stores the character 'A'. The data type is essential for working with characters and strings in C.
Question 24: In C, which operator is used for pointer-to-pointer relationships?
- A ->
- B *
- C &
- D ::
Explanation: In C, the operator used for pointer-to-pointer relationships is . The asterisk () operator is used for both declaring and dereferencing pointer variables. When you have a pointer-to-pointer (a pointer that points to another pointer), you use multiple asterisks to access the value pointed to by the second pointer. So, the correct answer is: Here's an example of a pointer-to-pointer relationship in C: In this example, ptr2 is a pointer-to-pointer, and **ptr2 is used to access the value stored in num.
Question 25: What is the size of an int data type?
- A 4 Bytes
- B 8 Bytes
- C Depends on the system/compiler
- D Cannot be determined
Explanation: No explanation is given for this question
Question 26: Which of the following is a ternary operator?
- A >>=
- B ->
- C &&
- D ?:
Explanation: No explanation is given for this question
Question 27: Which symbol is used for the 'modulo' operation in C?
- A *
- B %
- C ^
- D /
Explanation: 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: Here's an example of using the modulo operator in C: In this example, the value of 'remainder' will be 1 because 10 divided by 3 is 3 with a remainder of 1.
Question 28: Find the output of the following program.
- A 65 65
- B 53 65
- C 053 65
- D 065 65
Explanation: As octal 65 ( 065 ) is equivalent of decimal value 53.
Question 29: What is the maximum number of arguments that can be passed to a C function?
- A 255
- B 10
- C No limit
- D 127
Explanation: The maximum number of arguments that can be passed to a C function is . In C, there is no hard-coded limit on the number of arguments you can pass to a function. However, practical limitations may exist based on factors like system memory and stack size. So, the correct answer is:
Question 30: Which is the only function all C programs must contain?
- A start()
- B printf()
- C main()
- D system()
Explanation: No explanation is given for this question
Question 31: What is the purpose of the 'scanf' function in C?
- A Read formatted input
- B Print formatted output
- C Execute a loop
- D Allocate memory
Explanation: No explanation is given for this question
Question 32: For 16-bit compiler allowable range for integer constants is ________?
- A -3.4e38 to 3.4e38
- B -32767 to 32768
- C -32768 to 32767
- D -32668 to 32667
Explanation: In a 16 Bit C compiler we have 2 bytes to store an integer, and 1 byte for a character. For unsigned integers the range is 0 to 65535. For unsigned character, 0 to 255
Question 33: Relational operators cannot be used on . . . . . . . .
- A long
- B structure
- C float
- D strings
Explanation: No explanation is given for this question
Question 34: Which of the following is not a correct variable type?
- A double
- B float
- C int
- D real
Explanation: in C define the kind of data that can be stored in a variable. - This is a correct variable type in C, used for storing single-precision floating-point numbers. - This is not a correct variable type in C. There is no data type called in C. - This is a correct variable type in C, used for storing integers. - This is a correct variable type in C, used for storing double-precision floating-point numbers. - This is a correct variable type in C, used for storing single characters. Therefore, the correct answer is .
Question 35: What is the purpose of the 'const' keyword in C?
- A Initialize a pointer
- B Define a function
- C Declare a variable
- D Declare a constant
Explanation: The purpose of the 'const' keyword in C is to . When you use the 'const' keyword before a variable declaration, it indicates that the value of that variable cannot be changed once it is assigned a value. It creates an immutable constant in your code. So, the correct answer is: Here's an example of using the 'const' keyword to declare a constant in C: In this example, 'max_attempts' is declared as a constant integer, and its value cannot be modified after initialization.
Question 36: What will be printed after execution of the following program code?
- A asiha
- B absiha
- C haasi
- D hai
Explanation: - newline - ""; - Prints - backspace - ""; - firstly '' removes 'b' from 'ab ' and then prints 'si'. So after execution of ""; it is. - linefeed - ""; - Now here '' moves the cursor to the start of the current line and then override 'asi' to .
Question 37: What is the purpose of the 'break' statement in C?
- A End the program
- B Exit a loop
- C Exit a function
- D Skip the loop
Explanation: The purpose of the 'break' statement in C is to . When 'break' is encountered within a loop (such as 'for' or 'while' loop), it immediately terminates the loop and continues with the next statement after the loop's body. So, the correct answer is: Here's an example of using the 'break' statement to exit a loop in C:
Question 38: What is the correct syntax for declaring a variable in C?
- A variable_name int;
- B int = variable_name;
- C variable_name = 5;
- D int variable_name;
Explanation: The correct syntax for declaring a variable in C is . 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: Here's an example: In this example, we declare an integer variable named "age." This syntax informs the compiler that "age" is of type . 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.
Question 39: "My salary was increased by 15%" Select the statement, which will EXACTLY reproduce the line of text above.
- A printf("My salary was increased by 15%!");
- B printf("My salary was increased by 15'%'!");
- C printf("My salary was increased by 15%%!");
- D printf("My salary was increased by 15/%!");
Explanation: No explanation is given for this question
Question 40: Which of the following data type will throw an error on modulus operation(%)?
- A float
- B char
- C int
- D short
Explanation: No explanation is given for this question
Question 41: One of the major difference between typedef and #define is that typedef interpretation is performed by the . . . . . . . . whereas #define interpretation is performed by the . . . . . . . .
- A compiler, user
- B user, pre-processor
- C compiler, pre-processor
- D pre-processor, compiler
Explanation: No explanation is given for this question
Question 42: What is the default return type of a function in C if not specified?
- A char
- B void
- C float
- D int
Explanation: The default return type of a function in C if not specified is . In C, if you don't explicitly specify the return type of a function, it is assumed to return an integer () by default. So, the correct answer is: For example, if you have a function like this: The return type is assumed to be , and you can call it as if it returns an integer. If you want a function to return nothing, you explicitly specify as the return type.
Question 43: Which of the following typecasting is accepted by C?
- A Widening conversions
- B Widening & Narrowing conversions
- C None of the mentioned
- D Narrowing conversions
Explanation: No explanation is given for this question
Question 44: Operation "a = a * b + a" can also be written as . . . . . . . .
- A a *= b + 1;
- B All of the mentioned
- C a = (b + 1)* a;
- D (c = a * b)!=(a = c + a);
Explanation: No explanation is given for this question
Question 45: Which character is used to indicate the end of a statement in C?
- A ,
- B .
- C ;
- D :
Explanation: 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: In C programming, you terminate a statement with a semicolon. For example: In the above code, the semicolon at the end of each line signifies the end of the respective statement.
Question 46: Which header file is used for mathematical functions in C?
- A <stdlib.h>
- B <stdio.h>
- C <math.h>
- D <string.h>
Explanation: No explanation is given for this question
Question 47: Which of the following is an invalid assignment operator?
- A a |= 10;
- B None of the mentioned
- C a /= 10;
- D a %= 10;
Explanation: No explanation is given for this question
Question 48: For which of the following, "PI++;" code will fail?
- A none of the Mentioned
- B #define PI 3.14
- C float PI = 3.14;
- D char *PI = "A";
Explanation: No explanation is given for this question
Question 49: If integer needs two bytes of storage, then maximum value of an unsigned integer is
- A 2
- B 2
- C 2
- D 2
Explanation: An integer is a number with no fractional part; it can be positive, negative or zero. In ordinary usage, one uses a minus sign to designate a negative integer. However, a computer can only store information in bits, which can only have the values zero or one. We might expect, therefore, that the storage of negative integers in a computer might require some special technique. As you might imagine, an unsigned integer is either positive or zero. Consider a single digit decimal number: In a single decimal digit, you can write a number between 0 and 9. In two decimal digits, you can write a number between 0 and 99, and so on. Since nine is equivalent to 10 - 1, 99 is equivalent to 10 - 1, etc. In n decimal digits, you can write a number between 0 and 10 - 1. So, analogously, in the binary number system, An unsigned integer containing n bits can have a value between 0 and 2 - 1 (which is 2 different values).
Question 50: What is the range of values that can be stored in an 'int' data type in C?
- A 0 to 65535
- B 0 to 4294967295
- C -32768 to 32767
- D -2147483648 to 2147483647
Explanation: The range of values that can be stored in an 'int' data type in C is . An 'int' is typically represented as a 32-bit signed integer on most systems, which allows it to store values within this range. So, the correct answer is: