C And C Sharp Quizes

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Pavani_shetty
P
Pavani_shetty
Community Contributor
Quizzes Created: 1 | Total Attempts: 1,059
| Attempts: 1,059 | Questions: 25
Please wait...
Question 1 / 25
0 %
0/100
Score 0/100
1.  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;
}

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.

Submit
Please wait...
About This Quiz
C And C Sharp Quizes - Quiz

This quiz assesses knowledge in C and C# programming, focusing on core topics like function usage, error identification, and handling specific programming scenarios. It's designed to enhance understanding of programming constructs and debugging skills, essential for any budding programmer.

Personalize your quiz and earn a certificate with your name on it!
2. Which header file should be included to use functions like malloc() and calloc()?

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.

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

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.

Submit
4. 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);
}

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.

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

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.

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

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.

Submit
7. 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;
}

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.

Submit
8. 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;
}

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

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

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.

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

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.

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

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.

Submit
12. What does fp point to in the program ? 
#include<stdio.h>

int main()
{
    FILE *fp;
    fp=fopen("trial", "r");
    return 0;
}

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.

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

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.

Submit
14. How many times the program will print "vardhaman" ?  
#include<stdio.h>

int main()
{
    printf("vardhaman");
    main();
    return 0;
}

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.

Submit
15. 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;
}

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.

Submit
16. 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);
}

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.

Submit
17.  In which header file is the NULL macro defined?

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.

Submit
18. Which of the following statements are correct about the program? 
#include<stdio.h>

int main()
{
    printf("%d\n", main());
    return 0;
}

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.

Submit
19. 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;
}

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.

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

Explanation

The function fmod(3.14, 2.1) should be used to obtain the remainder after dividing 3.14 by 2.1.

Submit
21. 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;
}

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.

Submit
22. 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;
}

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.

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

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

Submit
24. Which of the following is the correct usage of conditional operators used in 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.

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

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.

Submit
View My Results

Quiz Review Timeline (Updated): Feb 17, 2023 +

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
Cancel
  • All
    All (25)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
 Which statement will you add in the following program to work it...
Which header file should be included to use functions like malloc()...
What function should be used to free the memory allocated by calloc()...
What will be the output of the program ? #include<stdio.h> ...
What do the 'c' and 'v' in argv stands for?
The keyword used to transfer control from a function back to the...
What will be the output of the program ? ...
What will be the output of the program ? ...
What does the following declaration mean?int (*ptr)[10];
Point out the error in the following...
In which numbering system can the binary number 1011011111000101 be...
What does fp point to in the program ? #include<stdio.h> ...
Which of the following are unary operators in C?1. !2. sizeof3. ~4....
How many times the program will print "vardhaman"...
What will be the output of the program? #include<stdio.h> ...
What will be the output of the...
 In which header file is the NULL macro defined?
Which of the following statements are correct about the program? ...
What will the SWAP macro in the following program be expanded to on...
 Which of the following statements should be used to obtain a...
Point out the error in the program  ...
Assunming, integer is 2 byte, What will be the output of the...
Which bitwise operator is suitable for checking whether a particular...
Which of the following is the correct usage of conditional operators...
Which standard library function will you use to find the last...
Alert!

Advertisement