Medha -the Programming Quiz

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 Medha1
M
Medha1
Community Contributor
Quizzes Created: 1 | Total Attempts: 709
Questions: 20 | Attempts: 709

SettingsSettingsSettings
Medha -the Programming Quiz - Quiz


Questions and Answers
  • 1. 

     What is the output of the below code snippet?#include<stdio.h> main(){   int a = 5, b = 3, c = 4;     printf("a = %d, b = %d\n", a, b, c);}

    • A.

      a=5, b=3

    • B.

      a=5, b=3,c=0

    • C.

      a=5, b=3,0

    • D.

      Compile error

    Correct Answer
    A. a=5, b=3
    Explanation
    The code snippet will output "a = 5, b = 3". This is because the printf statement is printing the values of variables 'a' and 'b' using the format specifier "%d". The values of 'a' and 'b' are 5 and 3 respectively. The variable 'c' is not being printed in the printf statement, so its value does not affect the output.

    Rate this question:

  • 2. 

    What is the output of the following program?#include<stdio.h> main(){   struct { int x;} var = {5}, *p = &var;     printf("%d %d %d",var.x,p->x,(*p).x);}

    • A.

      5 5 5

    • B.

      5 5 garbage value

    • C.

      5 5 0

    • D.

      Compile error

    Correct Answer
    A. 5 5 5
    Explanation
    The program defines a structure variable named "var" with an integer member "x" and initializes it to 5. It also declares a pointer variable "p" of the same structure type and assigns the address of "var" to it.

    The printf statement prints the value of "var.x", "p->x", and "(*p).x". Since "var.x" is 5, "p->x" and "(*p).x" both access the value of "x" through the pointer "p", which points to "var". Therefore, all three values are 5.

    Rate this question:

  • 3. 

    What is the built in library function to adjust the allocated dynamic memory size.

    • A.

      Malloc

    • B.

      Calloc

    • C.

      Realloc

    • D.

      Resize

    Correct Answer
    C. Realloc
    Explanation
    The correct answer is "realloc". The realloc function is a built-in library function in C that is used to adjust the size of dynamically allocated memory. It allows for the reallocation of memory blocks, either expanding or reducing their size. This function is particularly useful when the size of the memory needed by a program changes during its execution. By using realloc, the program can efficiently manage memory allocation and deallocation, optimizing the use of resources.

    Rate this question:

  • 4. 

    What is the output of the following program?#include<stdio.h>main(){ fprintf(stdout,"Hello, World!");}

    • A.

      Hello, world!

    • B.

      Compile error

    • C.

      No output

    • D.

      Runtime error

    Correct Answer
    A. Hello, world!
    Explanation
    The program uses the fprintf function to print the string "Hello, World!" to the standard output stream (stdout). Therefore, the output of the program will be "Hello, world!".

    Rate this question:

  • 5. 

    A Variable name in C includes which special symbols?

    • A.

      * (asterisk)

    • B.

      # (Hash)

    • C.

      + (Addition)

    • D.

      _ (underscore)

    Correct Answer
    D. _ (underscore)
    Explanation
    In C, a variable name can include the underscore symbol (_). This symbol is often used to separate words within a variable name to improve readability. For example, a variable name like "first_name" is more descriptive than "firstname". The other special symbols listed, such as asterisk, hash, and addition, are not allowed in variable names in C.

    Rate this question:

  • 6. 

    The correct order of mathematical operators in mathematics and computer programming,

    • A.

      Addition, Subtraction, Multiplication, Division

    • B.

      Division, Multiplication, Addition, Subtraction

    • C.

      Multiplication, Addition, Division, Subtraction

    • D.

      Mathematical operators can be done in any order

    Correct Answer
    B. Division, Multiplication, Addition, Subtraction
    Explanation
    In mathematics and computer programming, the correct order of mathematical operators is known as the order of operations. This order dictates that division should be done before multiplication, and multiplication should be done before addition and subtraction. This is because division and multiplication have higher precedence than addition and subtraction. Therefore, the correct order of mathematical operators is Division, Multiplication, Addition, Subtraction.

    Rate this question:

  • 7. 

    Choose the correct order of evaluation,

    • A.

      Relational Arithmetic Logical Assignment

    • B.

      Arithmetic Relational Logical Assignment

    • C.

      Logical Arithmetic Relational Assignment

    • D.

      Assignment Arithmetic Logical Relational

    Correct Answer
    B. Arithmetic Relational Logical Assignment
    Explanation
    The correct order of evaluation is Arithmetic Relational Logical Assignment. This means that arithmetic operations are performed first, followed by relational operations, then logical operations, and finally assignment operations. This order ensures that calculations are performed correctly and logical conditions are evaluated in the appropriate sequence.

    Rate this question:

  • 8. 

     What is the output of the below code snippet?#include<stdio.h> main(){   for(;;)printf("Hello");}

    • A.

      Infinite loop

    • B.

      Prints “Hello” once.

    • C.

      No output

    • D.

      Compile error

    Correct Answer
    A. Infinite loop
    Explanation
    The code snippet contains an infinite loop because there are no conditions specified in the for loop. The loop will continue to execute indefinitely, repeatedly printing "Hello" without any interruption or termination.

    Rate this question:

  • 9. 

    Compiler generates ___ file.

    • A.

      Executable code

    • B.

      Object code

    • C.

      Assembly code

    • D.

      None of above

    Correct Answer
    B. Object code
    Explanation
    A compiler generates object code files. Object code is the output of the compilation process, where the source code is translated into a lower-level representation that can be directly executed by the computer's hardware or combined with other object code files to create an executable program. Object code is specific to the target architecture and can be further processed by a linker to generate the final executable code. Assembly code is a human-readable representation of the machine code and is generated by an assembler, not a compiler. Therefore, the correct answer is object code.

    Rate this question:

  • 10. 

    C is the successor of ___ programming language.

    • A.

      C++

    • B.

      B++

    • C.

      B

    • D.

      MINI C

    Correct Answer
    C. B
    Explanation
    C++ is the successor of the C programming language. C++ was developed as an extension of the C language, adding object-oriented programming features and other enhancements. B++ and MINI C are not programming languages, and B is not the successor of the C language.

    Rate this question:

  • 11. 

    Which library function can convert an integer/long to a string?

    • A.

      ltoa()

    • B.

      Ultoa()

    • C.

      Sprintf()

    • D.

      None of the above

    Correct Answer
    A. ltoa()
    Explanation
    The ltoa() function is used to convert a long integer to a string. This function takes the long integer as input and converts it into a string representation. Therefore, ltoa() is the correct library function to convert an integer/long to a string.

    Rate this question:

  • 12. 

    What is the output of the following program?#include<stdio.h>void f(){ static int i = 3;    printf("%d ", i);   if(--i) f();}main(){ f();}

    • A.

      3 2 1 0

    • B.

      3 2 1

    • C.

      3 3 3

    • D.

      Compile error

    Correct Answer
    B. 3 2 1
    Explanation
    The program defines a function f() that has a static variable i initialized to 3. The function prints the value of i and then recursively calls itself with i decremented by 1. This process continues until i becomes 0. So, the output of the program will be 3 2 1.

    Rate this question:

  • 13. 

    Identify the incorrect file opening mode from the following.

    • A.

      R

    • B.

      W

    • C.

      X

    • D.

      A

    Correct Answer
    C. X
    Explanation
    The incorrect file opening mode is "x". The file opening modes "r", "w", and "a" are valid modes in Python. "r" is used for reading a file, "w" is used for writing to a file (and overwriting the existing content), and "a" is used for appending content to a file. However, "x" is not a valid file opening mode in Python.

    Rate this question:

  • 14. 

    In C, what are the various types of real data type (floating point data type)?

    • A.

      Float, long double

    • B.

      Long double, short int

    • C.

      Float, double, long double

    • D.

      Short int, double, long int, float

    Correct Answer
    C. Float, double, long double
    Explanation
    The correct answer is float, double, long double. In the C programming language, the various types of real data types or floating point data types are float, which is used to store single-precision floating point numbers, double, which is used to store double-precision floating point numbers, and long double, which is used to store extended-precision floating point numbers. These data types are used to represent numbers with fractional parts or numbers that are too large or too small to be represented using integer data types.

    Rate this question:

  • 15. 

    To print a double value which format specifier can be used?

    • A.

      %L

    • B.

      %If

    • C.

      %Lf

    • D.

      None of the above

    Correct Answer
    B. %If
    Explanation
    The correct answer is "%If". This format specifier is used to print a double value in C programming language. The "%" symbol is used to indicate a format specifier, and "f" is used to specify that the value is a double. Therefore, "%If" is the correct format specifier to print a double value.

    Rate this question:

  • 16. 

    What is the output of the following program?#include<stdio.h>void main(){   char s[ ] = "C++";    printf("%s ",s);   s++;   printf("%s",s);}

    • A.

      C++ C++

    • B.

      C++ ++

    • C.

      ++ ++

    • D.

      Compile error

    Correct Answer
    D. Compile error
    Explanation
    The program will give a compile error because the line "s++;" is trying to increment the array name 's', which is not allowed in C++. Array names are constant pointers and cannot be modified.

    Rate this question:

  • 17. 

    Which of the following statement shows the correct implementation of nested conditional operation by finding greatest number out of three numbers?

    • A.

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

    • B.

      A=b ? c=30;

    • C.

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

    • D.

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

    Correct Answer
    A. Max = a>b ? a>c?a:c:b>c?b:c
    Explanation
    The correct implementation of nested conditional operation to find the greatest number out of three numbers is shown in the answer "max = a>b ? a>c?a:c:b>c?b:c". This statement uses nested ternary operators to compare the numbers and determine the maximum value. The first ternary operator compares a and b, and if a is greater, it compares a with c to determine the maximum. If b is greater, it compares b with c to determine the maximum. This way, the statement finds the greatest number among a, b, and c.

    Rate this question:

  • 18. 

    Specify the 2 library functions to dynamically allocate memory?

    • A.

      Malloc() and memalloc()

    • B.

      Alloc() and memalloc()

    • C.

      Malloc() and calloc()

    • D.

      Memalloc() and faralloc()

    Correct Answer
    C. Malloc() and calloc()
    Explanation
    The correct answer is malloc() and calloc(). These are two library functions used to dynamically allocate memory in C programming. malloc() is used to allocate a block of memory of a specified size, while calloc() is used to allocate and initialize a block of memory for an array of elements. Both functions are commonly used in C programming for dynamic memory allocation.

    Rate this question:

  • 19. 

    In C, if you pass an array as an argument to a function, what actually gets passed?

    • A.

      Value of elements in array

    • B.

      First element of the array

    • C.

      Base address of the array

    • D.

      Address of the last element of array

    Correct Answer
    C. Base address of the array
    Explanation
    When an array is passed as an argument to a function in C, only the base address of the array is actually passed. This means that the memory address of the first element of the array is passed to the function. By using this base address, the function can access and manipulate the elements of the array.

    Rate this question:

  • 20. 

    Which of the following function is used to find the first occurrence of a given string in another string?

    • A.

      Strchr()

    • B.

      Strrchr()

    • C.

      Strstr()

    • D.

      Strnset()

    Correct Answer
    C. Strstr()
    Explanation
    The strstr() function is used to find the first occurrence of a given string within another string. It searches for the first instance of the specified substring and returns a pointer to the location within the original string where the substring is found.

    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
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Feb 27, 2017
    Quiz Created by
    Medha1
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.