C And C Sharp Quizes

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Pavani_shetty
P
Pavani_shetty
Community Contributor
Quizzes Created: 1 | Total Attempts: 1,048
Questions: 25 | Attempts: 1,048

SettingsSettingsSettings
C And C Sharp Quizes - Quiz


Questions and Answers
  • 1. 

     Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?

    • A.

      Rem = 3.14 % 2.1;

    • B.

      Rem = modf(3.14, 2.1);

    • C.

      Rem = fmod(3.14, 2.1);

    • D.

      Remainder cannot be obtain in floating point division.

    Correct Answer
    C. Rem = fmod(3.14, 2.1);
    Explanation
    The function fmod(3.14, 2.1) should be used to obtain the remainder after dividing 3.14 by 2.1.

    Rate this question:

  • 2. 

    Point out the error in the following program     #include<stdio.h> int main() { display(); return 0; } void display() { printf("Welcome To Tait"); }

    • A.

      No error

    • B.

      Display() doesn't get invoked

    • C.

      Display() is called before it is defined

    • D.

      None of these

    Correct Answer
    C. Display() is called before it is defined
    Explanation
    The error in the program is that the function display() is called before it is defined. In C programming, functions need to be declared or defined before they are used. In this program, the main() function calls the display() function before it is actually defined. To fix this error, the display() function should be defined or declared before the main() function.

    Rate this question:

  • 3. 

     Which statement will you add in the following program to work it correctly?      #include<stdio.h> int main() { printf("%f\n", log(36.0)); return 0; }

    • A.

      #include(conio.h)

    • B.

      #include(math.h)

    • C.

      #include(stdlib.h)

    • D.

      #include(string.h)

    Correct Answer
    B. #include(math.h)
    Explanation
    The correct answer is #include(math.h). This is because the log() function is used in the program, which is a mathematical function. Including the math.h header file allows the program to access the necessary function and perform the logarithmic calculation correctly.

    Rate this question:

  • 4. 

     In which header file is the NULL macro defined?

    • A.

      Stdio.h

    • B.

      Stddef.h

    • C.

      Stdio.h and stddef.h

    • D.

      Math.h

    Correct Answer
    C. Stdio.h and stddef.h
    Explanation
    The NULL macro is defined in both stdio.h and stddef.h header files. These header files are part of the C standard library and provide various functions and macros. stdio.h is used for input and output operations, while stddef.h is used for defining several types and macros, including NULL. Therefore, to use the NULL macro in a C program, either stdio.h or stddef.h (or both) can be included.

    Rate this question:

  • 5. 

    Point out the error in the program  #include<stdio.h> int main() { int a[] = {10, 20, 30, 40, 50}; int j; for(j=0; j<5; j++) { printf("%d\n", a); a++; } return 0; }

    • A.

      Error: Declaration syntax

    • B.

      Error: Expression syntax

    • C.

      Error: LValue required

    • D.

      Rvalue required

    Correct Answer
    C. Error: LValue required
    Explanation
    The error in the program is "Error: LValue required". This error occurs because the variable "a" is being incremented in the line "a++", which is not allowed because "a" is an array and arrays are not modifiable lvalues. Modifying an array name is not allowed in C.

    Rate this question:

  • 6. 

    Which bitwise operator is suitable for checking whether a particular bit is on or off?

    • A.

      && operator

    • B.

      & operator

    • C.

      || operator

    • D.

      ! operator

    Correct Answer
    B. & operator
    Explanation
    The & operator is suitable for checking whether a particular bit is on or off. This operator performs a bitwise AND operation between two operands. When used with a specific bit and the value 1, it will return 1 if the bit is on (1) and 0 if the bit is off (0).

    Rate this question:

  • 7. 

    Assunming, integer is 2 byte, What will be the output of the program? #include<stdio.h> int main() { printf("%x\n", -1>>1); return 0; }

    • A.

      Ffff

    • B.

      0fff

    • C.

      000f

    • D.

      Fff0

    Correct Answer
    A. Ffff
    Explanation
    The program uses the right shift operator (>>) to shift the bits of -1 by 1 position to the right. Since -1 is represented in two's complement form, all bits are set to 1. Shifting the bits to the right by 1 position will result in the value being divided by 2, and the sign bit (MSB) will be retained. Therefore, the output will be "ffff" in hexadecimal, which represents the decimal value -1.

    Rate this question:

  • 8. 

    What function should be used to free the memory allocated by calloc() ?

    • A.

      Dealloc();

    • B.

      Malloc(variable_name, 0)

    • C.

      Free();

    • D.

      Memalloc(variable_name, 0)

    Correct Answer
    C. Free();
    Explanation
    The function that should be used to free the memory allocated by calloc() is free(). This function is used to deallocate the memory block previously allocated by malloc(), calloc(), or realloc(). By using free(), the memory allocated by calloc() is released and can be reused for other purposes.

    Rate this question:

  • 9. 

    What will be the output of the program?     #include #include int main() { char *s; char *fun(); s = fun(); printf("%s\n", s); return 0; } char *fun() { char buffer[30]; strcpy(buffer, "RAM"); return (buffer); }

    • A.

      0xffff

    • B.

      Garbage value

    • C.

      Ram

    • D.

      Error

    Correct Answer
    B. Garbage value
    Explanation
    The program is trying to print the value of the string `s` which is assigned the return value of the `fun()` function. However, the `fun()` function is returning the address of a local variable `buffer` which is a character array. Once the `fun()` function finishes executing, the memory allocated for the `buffer` variable is deallocated, and accessing that memory location through `s` will result in undefined behavior. This can lead to garbage values being printed.

    Rate this question:

  • 10. 

    Which standard library function will you use to find the last occurance of a character in a string in C?

    • A.

      Strnchar()

    • B.

      Strchar()

    • C.

      Strrchar()

    • D.

      Strrchr()

    Correct Answer
    D. Strrchr()
    Explanation
    The strrchr() function is the correct answer because it is a standard library function in C that is used to find the last occurrence of a character in a string. This function takes two arguments - the string in which we want to search for the character, and the character we want to find. It returns a pointer to the last occurrence of the character in the string, or NULL if the character is not found.

    Rate this question:

  • 11. 

    How many times the program will print "vardhaman" ?  #include<stdio.h> int main() { printf("vardhaman"); main(); return 0; }

    • A.

      Infinite times

    • B.

      32767 times

    • C.

      65535 times

    • D.

      Till stack overflows

    Correct Answer
    D. Till stack overflows
    Explanation
    The program will print "vardhaman" until the stack overflows. This is because the main function calls itself recursively without any termination condition, causing an infinite loop. As the function keeps calling itself without returning, it consumes more and more stack space until it exceeds the maximum stack size, resulting in a stack overflow.

    Rate this question:

  • 12. 

    Which of the following statements are correct about the program? #include<stdio.h> int main() { printf("%d\n", main()); return 0; }

    • A.

      It prints garbage values infinitely

    • B.

      Runs infinitely without printing anything

    • C.

      Error: main() cannot be called inside printf()

    • D.

      No Error and print nothing

    Correct Answer
    B. Runs infinitely without printing anything
    Explanation
    The program runs infinitely because the main function is recursively calling itself within the printf statement. This creates an infinite loop where the program keeps calling main without any condition to stop. As a result, the program does not print anything and continues to run indefinitely.

    Rate this question:

  • 13. 

    What does the following declaration mean?int (*ptr)[10];

    • A.

      Ptr is array of pointers to 10 integers

    • B.

      Ptr is a pointer to an array of 10 integers

    • C.

      Ptr is an array of 10 integers

    • D.

      Ptr is an pointer to array

    Correct Answer
    B. Ptr is a pointer to an array of 10 integers
    Explanation
    The declaration "int (*ptr)[10];" means that ptr is a pointer to an array of 10 integers. This means that ptr can be used to access and manipulate the elements of an array that contains 10 integers.

    Rate this question:

  • 14. 

    What will be the output of the program ? #include<stdio.h> void fun(int **p); int main() { int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0}; int *ptr; ptr = &a[0][0]; fun(&ptr); return 0; } void fun(int **p) { printf("%d\n", **p); }

    • A.

      1

    • B.

      2

    • C.

      3

    • D.

      4

    Correct Answer
    A. 1
    Explanation
    The program defines a 2D array `a` and a pointer `ptr` which points to the first element of the array. The function `fun` is called with the address of `ptr` as an argument. Inside the function, the value at the address pointed by `p` is printed, which is the value at the first element of the array `a`. Therefore, the output of the program will be 1.

    Rate this question:

  • 15. 

    What will be the output of the program ? #include<stdio.h> int main() { float arr[] = {12.4, 2.3, 4.5, 6.7,11.2}; printf("%d\n", sizeof(arr)/sizeof(arr[0])); return 0; }

    • A.

      6

    • B.

      4

    • C.

      5

    • D.

      7

    Correct Answer
    C. 5
    Explanation
    The program declares an array of float values and initializes it with 5 elements. The sizeof operator is used to calculate the total number of bytes occupied by the array, and this value is divided by the number of bytes occupied by a single element of the array. Since each element of the array is of type float, which typically occupies 4 bytes, the result of the division is 5. Therefore, the output of the program will be 5.

    Rate this question:

  • 16. 

    What does fp point to in the program ? #include<stdio.h> int main() { FILE *fp; fp=fopen("trial", "r"); return 0; }

    • A.

      The first character in the file

    • B.

      A structure which contains a char pointer which points to the first character of a file.

    • C.

      The name of the file.

    • D.

      The last character in the file.

    Correct Answer
    B. A structure which contains a char pointer which points to the first character of a file.
    Explanation
    The variable "fp" is a pointer to a structure of type FILE. This structure contains a char pointer which points to the first character of a file. In this program, the fopen function is used to open the file named "trial" in read mode, and the file pointer "fp" is assigned the address of this opened file. Therefore, "fp" points to the first character of the file.

    Rate this question:

  • 17. 

    Which of the following are unary operators in C?1. !2. sizeof3. ~4. &&

    • A.

      1,2

    • B.

      1,3

    • C.

      2,4

    • D.

      1,2,3

    Correct Answer
    D. 1,2,3
    Explanation
    The correct answer is 1,2,3. In C, the unary operators are operators that operate on a single operand. The exclamation mark (!) is the logical NOT operator, the sizeof operator is used to determine the size of a variable or data type, and the tilde (~) is the bitwise NOT operator. Therefore, options 1, 2, and 3 are the unary operators in C. Option 4, &&, is the logical AND operator, which is a binary operator as it operates on two operands.

    Rate this question:

  • 18. 

    What will be the output of the program? #include<stdio.h> int main() { int i=-3, j=2, k=0, m; m = ++i || ++j && ++k; printf("%d, %d, %d, %d\n", i, j, k, m); return 0; }

    • A.

      2, 2, 0, 1

    • B.

      1, 2, 1, 0

    • C.

      -2, 2, 0, 0

    • D.

      -2, 2, 0, 1

    Correct Answer
    D. -2, 2, 0, 1
    Explanation
    In this program, the variables i, j, k, and m are initialized with the values -3, 2, 0, and uninitialized respectively.
    The expression "++i || ++j && ++k" is evaluated and assigned to m.
    Since "++i" is true (-2), the rest of the expression is not evaluated.
    Therefore, i becomes -2, j remains 2, k remains 0, and m becomes 1.
    The output of the program is -2, 2, 0, 1.

    Rate this question:

  • 19. 

    What will be the output of the program ? #include<stdio.h> #include<string.h> int main() { char str1[20] = "Hello", str2[20] = " World"; printf("%s\n", strcpy(str2, strcat(str1, str2))); return 0; }

    • A.

      Hello

    • B.

      World

    • C.

      Hello World

    • D.

      WorldHello

    Correct Answer
    C. Hello World
    Explanation
    The program first concatenates the strings str1 and str2 using the strcat() function, resulting in "Hello World". Then, it copies the concatenated string to str2 using the strcpy() function. Finally, it prints the value of str2, which is "Hello World".

    Rate this question:

  • 20. 

    What do the 'c' and 'v' in argv stands for?

    • A.

      'c' means argument control 'v' means argument vector

    • B.

      'c' means argument count 'v' means argument vertex

    • C.

      'c' means argument count 'v' means argument vector

    • D.

      'c' means argument configuration 'v' means argument visibility

    Correct Answer
    C. 'c' means argument count 'v' means argument vector
    Explanation
    The 'c' in argv stands for argument count, which refers to the number of command-line arguments passed to the program. The 'v' stands for argument vector, which is an array of strings that holds the actual command-line arguments.

    Rate this question:

  • 21. 

    What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile? #include<stdio.h> #define SWAP(a, b, c)(c t; t=a, a=b, b=t) int main() { int x=10, y=20; SWAP(x, y, int); printf("%d %d\n", x, y); return 0; }

    • A.

      It compiles

    • B.

      Compiles with an warning

    • C.

      Not compile

    • D.

      Compiles and print nothing

    Correct Answer
    C. Not compile
    Explanation
    The SWAP macro in the program is not correctly defined. The macro expects three arguments, but it is only given two arguments in the main function. Therefore, the code will not compile.

    Rate this question:

  • 22. 

    Which header file should be included to use functions like malloc() and calloc()?

    • A.

      Memory.h

    • B.

      Stdlib.h

    • C.

      Math.h

    • D.

      Dos.h

    Correct Answer
    B. Stdlib.h
    Explanation
    The correct answer is stdlib.h. This header file should be included to use functions like malloc() and calloc(). The stdlib.h header file in C provides functions for general-purpose use, including memory allocation and deallocation functions like malloc() and calloc(). These functions are used to dynamically allocate memory during program execution. Including stdlib.h allows the program to access these functions and perform memory allocation operations.

    Rate this question:

  • 23. 

    Which of the following is the correct usage of conditional operators used in C?

    • A.

      A>b ? c=30 : c=40;

    • B.

      A>b ? c=30;

    • C.

      Max = a>b ? a>c?a:c:b>c?b:c

    • D.

      Return (a>b)?(a:b)

    Correct Answer
    C. Max = a>b ? a>c?a:c:b>c?b:c
    Explanation
    The correct usage of conditional operators in C is demonstrated in the given answer: max = a>b ? a>c?a:c:b>c?b:c. This expression uses nested ternary operators to determine the maximum value among three variables. It first checks if a is greater than b, and if true, it checks if a is greater than c. If both conditions are true, the value of a is assigned to max. If the first condition is true but the second is false, the value of c is assigned to max. If the first condition is false, it checks if b is greater than c. If true, the value of b is assigned to max. If false, the value of c is assigned to max.

    Rate this question:

  • 24. 

    The keyword used to transfer control from a function back to the calling function is

    • A.

      Switch

    • B.

      Goto

    • C.

      Go back

    • D.

      Return

    Correct Answer
    D. Return
    Explanation
    The keyword "return" is used to transfer control from a function back to the calling function. When a function is called, the control is passed to that function and it starts executing its code. However, at some point, the function may need to return a value or simply terminate and pass control back to the calling function. This is achieved by using the "return" keyword, which not only transfers control back to the calling function but also can return a value if specified.

    Rate this question:

  • 25. 

    In which numbering system can the binary number 1011011111000101 be easily converted to?

    • A.

      Decimal system

    • B.

      Hexadecimal system

    • C.

      Octal system

    • D.

      No need to convert

    Correct Answer
    B. Hexadecimal system
    Explanation
    The binary number 1011011111000101 can be easily converted to the hexadecimal system because each hexadecimal digit represents four binary digits. In this case, the binary number can be divided into groups of four digits from right to left (1011, 0111, 1100, 0101), which can then be converted to their corresponding hexadecimal digits (B, 7, C, 5). Therefore, the binary number 1011011111000101 can be easily converted to the hexadecimal system.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Feb 17, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 17, 2016
    Quiz Created by
    Pavani_shetty
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.