C And C++ Memory Storage Coding

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 Bug_quesh
B
Bug_quesh
Community Contributor
Quizzes Created: 1 | Total Attempts: 205
Questions: 30 | Attempts: 205

SettingsSettingsSettings
C And C++ Memory Storage Coding - Quiz

Do you like coding of  C and C++ and you want to learn more about it?  Let's start this quiz and learn!


Questions and Answers
  • 1. 

    Which is more memory efficient ?

    • A.

      Structure

    • B.

      Union

    • C.

      Both use same memory

    • D.

      Depends on a programmer

    Correct Answer
    B. Union
    Explanation
    A union is more memory efficient compared to a structure because it allows different variables to share the same memory space. In a structure, each variable has its own memory space, leading to potential wastage of memory. However, in a union, all variables share the same memory space, which reduces memory consumption. This is particularly useful when only one variable is accessed at a time, as it allows for efficient memory utilization.

    Rate this question:

  • 2. 

    How we can define member function outside the class ?

    • A.

      Using union

    • B.

      Using structure

    • C.

      Using pointers

    • D.

      Using scope resolution

    Correct Answer
    D. Using scope resolution
    Explanation
    Member functions in C++ can be defined outside the class using the scope resolution operator (::). This allows the definition of the function to be separate from the class declaration, providing better organization and readability of the code. By using the scope resolution operator, the function is associated with the specific class and can access its private members.

    Rate this question:

  • 3. 

    Which of the following operations can be performed on the file "NOTES.TXT" using the below code?FILE *fp; fp = fopen("NOTES.TXT", "r+");

    • A.

      Reading

    • B.

      Writing

    • C.

      Appending

    • D.

      Read and Write

    Correct Answer
    D. Read and Write
    Explanation
    The code snippet opens the file "NOTES.TXT" with the mode "r+" which allows both reading and writing operations on the file. Therefore, the operations that can be performed on the file using this code are reading and writing.

    Rate this question:

  • 4. 

    Which among the following is NOT a logical or relational operator?

    • A.

      !=

    • B.

      =

    • C.

      ||

    • D.

      ==

    Correct Answer
    B. =
    Explanation
    The operator "=" is not a logical or relational operator. It is the assignment operator used to assign a value to a variable. Logical and relational operators are used to compare values or check conditions, such as "!=" (not equal to), "||" (logical OR), and "==" (equal to).

    Rate this question:

  • 5. 

    Which of the following concepts means determining at runtime what method to invoke?

    • A.

      Data hiding

    • B.

      Dynamic Typing

    • C.

      Dynamic binding

    • D.

      Dynamic loading

    Correct Answer
    C. Dynamic binding
    Explanation
    Dynamic binding refers to the process of determining at runtime which method to invoke. It allows the program to select the appropriate method based on the actual type of the object, rather than the declared type. This enables polymorphism, where different objects can respond differently to the same method call. Dynamic binding is an essential feature of object-oriented programming languages, as it allows for flexibility and extensibility in the code.

    Rate this question:

  • 6. 

    To print out a and b given below, which of the following printf() statement will you use?#include<stdio.h> float a=3.14; double b=3.14;

    • A.

      Printf("%f %lf", a, b);

    • B.

      Printf("%Lf %f", a, b);

    • C.

      Printf("%Lf %Lf", a, b);

    • D.

      Printf("%f %Lf", a, b);

    Correct Answer
    A. Printf("%f %lf", a, b);
    Explanation
    The correct answer is printf("%f %lf", a, b) because the variable "a" is a float and the variable "b" is a double. The format specifier "%f" is used to print float values and "%lf" is used to print double values.

    Rate this question:

  • 7. 

    A .............. is an alias or synonym for another variable.

    • A.

      reference

    • B.

      Structure

    • C.

      Pointer

    • D.

      Array

    Correct Answer
    A. reference
    Explanation
    A reference is an alias or synonym for another variable. In other words, it is a way to refer to the same memory location or data as another variable, but with a different name. By using a reference, we can access and manipulate the value of the original variable through the reference variable. This can be useful in situations where we want to have multiple names for the same data or when we want to pass variables by reference to functions.

    Rate this question:

  • 8. 

    What will be the output of the program ?#include<stdio.h> int main() { int k=1; printf("%d == 1 is" "%s\n", k, k==1?"TRUE":"FALSE"); return 0; }

    • A.

      K == 1 is TRUE

    • B.

      1 == 1 is TRUE

    • C.

      1 == 1 is FALSE

    • D.

      K == 1 is FALSE

    Correct Answer
    B. 1 == 1 is TRUE
    Explanation
    The program will output "1 == 1 is TRUE". This is because the variable "k" is initialized to 1, and the expression "k==1" evaluates to true. Therefore, the program will print "TRUE" as the output.

    Rate this question:

  • 9. 

    Which of the following concept of oops allows compiler to insert arguments in a function call if it is not specified?

    • A.

      Call by value

    • B.

      Call by reference

    • C.

      Default arguments

    • D.

      Call by pointer

    Correct Answer
    C. Default arguments
    Explanation
    Default arguments in object-oriented programming allow the compiler to automatically insert arguments in a function call if they are not specified by the programmer. This feature is useful when a function has parameters that have default values assigned to them. If the programmer does not provide a value for a particular parameter, the compiler will automatically use the default value defined in the function declaration. This allows for more flexibility and convenience when calling functions, as it reduces the need for explicitly specifying all arguments in every function call.

    Rate this question:

  • 10. 

    Cout is a/an __________ .

    • A.

      Operator

    • B.

      Function

    • C.

      Object

    • D.

      Macro

    Correct Answer
    C. Object
    Explanation
    The correct answer is "object" because "cout" is an object of the "ostream" class in C++. It is used to display output on the console.

    Rate this question:

  • 11. 

    What are mandatory parts in function declaration?

    • A.

      Return type,function name

    • B.

      Return type,function name,parameters

    • C.

      Both a and b

    • D.

      None of the mentioned

    Correct Answer
    A. Return type,function name
    Explanation
    The mandatory parts in a function declaration are the return type and the function name. These two components are essential in defining a function in any programming language. The return type specifies the type of value that the function will return, while the function name is used to identify and call the function in the code. The parameters, on the other hand, are optional and may or may not be included in the function declaration depending on the requirements of the program.

    Rate this question:

  • 12. 

    If a is an integer variable, a=7/3; will return a value

    • A.

      2.5

    • B.

      0

    • C.

      3

    • D.

      2

    Correct Answer
    D. 2
    Explanation
    The expression "a=7/3" assigns the value of the division of 7 by 3 to the variable "a". In integer division, any decimal part is truncated, so the result is 2. Therefore, the correct answer is 2.

    Rate this question:

  • 13. 

    Which of the following are available only in the class hierarchy chain?

    • A.

      Public data members

    • B.

      Private data members

    • C.

      Protected data members

    • D.

      Member functions

    Correct Answer
    C. Protected data members
    Explanation
    Protected data members are available only in the class hierarchy chain. This means that they can be accessed by the derived classes that inherit from the base class, but not by objects of the base class or objects of other unrelated classes. Protected data members provide a level of encapsulation and allow derived classes to have access to certain data that is not accessible to the outside world.

    Rate this question:

  • 14. 

    What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?

    • A.

      Compile-time error.

    • B.

      Preprocessing error

    • C.

      Runtime error.

    • D.

      Runtime exception

    Correct Answer
    A. Compile-time error.
    Explanation
    When a class with parameterized constructors and no default constructor is used in a program, it means that the class requires specific arguments to be passed during object creation. If we try to create an object of this class without providing the required arguments, a compile-time error will occur. This is because the compiler cannot find a suitable constructor to create the object, resulting in a compile-time error.

    Rate this question:

  • 15. 

    Can you combine the following two statements into one?char *p; p = (char*) malloc(100);

    • A.

      Char p = *malloc(100);

    • B.

      Char *p = (char) malloc(100);

    • C.

      Char *p = (char*)malloc(100);

    • D.

      Char *p = (char *)(malloc*)(100);

    Correct Answer
    C. Char *p = (char*)malloc(100);
    Explanation
    The correct answer is "char *p = (char*)malloc(100)". This is because it correctly combines the two statements into one. The first statement declares a pointer variable "p" of type char. The second statement allocates memory of size 100 using malloc and assigns the address of the allocated memory to the pointer variable "p".

    Rate this question:

  • 16. 

    Which is not a storage class? 

    • A.

      Auto

    • B.

      Struct

    • C.

      Typedef

    • D.

      Static

    Correct Answer
    B. Struct
    Explanation
    The storage classes in C programming language are auto, register, static, and extern. Struct is not a storage class; it is a keyword used to define a user-defined data type that groups different types of variables together.

    Rate this question:

  • 17. 

    What does the client module import?

    • A.

      Macro

    • B.

      Record

    • C.

      Interface

    • D.

      None of the mentioned

    Correct Answer
    C. Interface
    Explanation
    The client module imports the interface.

    Rate this question:

  • 18. 

    How many types of constructor are there in C++?

    • A.

      1

    • B.

      4

    • C.

      3

    • D.

      2

    Correct Answer
    C. 3
    Explanation
    In C++, there are three types of constructors. The first type is the default constructor, which is automatically called when an object is created without any arguments. The second type is the parameterized constructor, which allows us to initialize the object with specific values. The third type is the copy constructor, which is used to create a new object by copying the values of an existing object. Therefore, the correct answer is 3.

    Rate this question:

  • 19. 

    Which of the following is the correct order if calling functions in the below code?a = f1(23, 14) * f2(12/4) + f3();

    • A.

      F1,f2,f3

    • B.

      F3, f2, f1

    • C.

      Order may vary from compiler to compiler

    • D.

      None of above

    Correct Answer
    C. Order may vary from compiler to compiler
    Explanation
    The correct answer is "Order may vary from compiler to compiler." In this code, the functions f1, f2, and f3 are being called in an expression to calculate the value of variable a. The order in which these functions are executed can vary depending on the compiler being used. Different compilers may have different rules or optimizations that determine the order of function execution. Therefore, the order of calling functions cannot be determined definitively and may vary.

    Rate this question:

  • 20. 

    #include is called

    • A.

      Preprocessor directive

    • B.

      Inclusion directive

    • C.

      File inclusion directive

    • D.

      None of the mentioned

    Correct Answer
    A. Preprocessor directive
    Explanation
    The given correct answer is "Preprocessor directive" because the "#include" statement is a preprocessor directive in C and C++ programming languages. Preprocessor directives are instructions that are processed by the preprocessor before the compilation of the code. The "#include" directive is used to include header files in the code, allowing the use of functions and definitions from those files in the program. Therefore, the statement "#include is called" is referring to the preprocessor directive that includes external files in the code.

    Rate this question:

  • 21. 

    What is output for  the following code:#include <stdio.h>int main(){static int a = 3;printf(“%d”, a --);return 0;} 

    • A.

      0

    • B.

      1

    • C.

      2

    • D.

      3

    Correct Answer
    D. 3
    Explanation
    The code snippet declares a static integer variable "a" with an initial value of 3. The printf statement prints the value of "a" and then decrements it by 1. Since the decrement operator "--" is placed after the variable, the value of "a" is printed before it is decremented. Therefore, the output of the code will be 3.

    Rate this question:

  • 22. 

    What is the output of this C code?  void main()    {        int x = 4.3 % 2;        printf("Value of x is %d", x);    } 

    • A.

      Value of x is 1.3

    • B.

      Value of x is 2

    • C.

      Value of x is 0.3

    • D.

      Compile time error

    Correct Answer
    D. Compile time error
    Explanation
    The code will result in a compile time error. In C, the modulus operator (%) can only be used with integer operands. In this code, the variable x is declared as an integer, but the value 4.3 is a floating-point number. Therefore, the code will not compile because the modulus operator cannot be used with a floating-point operand.

    Rate this question:

  • 23. 

    Which of the following statement is correct?

    • A.

      Strcmp(s1, s2) returns a number less than 0 if s1>s2

    • B.

      strcmp(s1, s2) returns a number greater than 0 if s1

    • C.

      Strcmp(s1, s2) returns 0 if s1==s2

    • D.

      Strcmp(s1, s2) returns 1 if s1==s2

    Correct Answer
    C. Strcmp(s1, s2) returns 0 if s1==s2
    Explanation
    The correct statement is that strcmp(s1, s2) returns 0 if s1 is equal to s2. This is because strcmp() is a function in C programming language that compares two strings. It returns a value less than 0 if the first string (s1) is greater than the second string (s2), a value greater than 0 if the first string is less than the second string, and 0 if the strings are equal. Therefore, the correct answer is that strcmp(s1, s2) returns 0 if s1 is equal to s2.

    Rate this question:

  • 24. 

    Relational operators cannot be used on:

    • A.

      structure

    • B.

      Long

    • C.

      strings

    • D.

      Float

    Correct Answer
    A. structure
    Explanation
    Relational operators, such as greater than (>), less than (

    Rate this question:

  • 25. 

    Which of the following statement is correct?

    • A.

      A reference is stored on heap.

    • B.

      A reference is stored on stack.

    • C.

      A reference is stored in a queue.

    • D.

      A reference is stored in a binary tree.

    Correct Answer
    B. A reference is stored on stack.
    Explanation
    A reference is stored on the stack because when a variable is declared and assigned a value, the reference to that variable is stored on the stack. The stack is a region of memory that is used for local variables and function calls. When a function is called, the variables and their references are pushed onto the stack, and when the function returns, they are popped off the stack. Therefore, a reference is stored on the stack.

    Rate this question:

  • 26. 

    Input/output function prototypes and macros are defined in which header file?

    • A.

      Conio.h

    • B.

      Stdlib.h

    • C.

      Stdio.h

    • D.

      Dos.h

    Correct Answer
    C. Stdio.h
    Explanation
    The correct answer is stdio.h. This header file contains the necessary function prototypes and macros for input/output operations in C programming. It includes functions like printf() and scanf() that are used for displaying output and taking input respectively.

    Rate this question:

  • 27. 

    Which is the only function all C programs must contain?

    • A.

      Start()

    • B.

      System()

    • C.

      Main()

    • D.

      Printf()

    Correct Answer
    C. Main()
    Explanation
    In C programming, the main() function is the entry point of any program. It is the function that is automatically called when the program starts executing. Therefore, all C programs must contain a main() function. This function is responsible for executing the code and controlling the flow of the program. It typically contains the instructions and logic that need to be executed by the program.

    Rate this question:

  • 28. 

    For 16-bit compiler allowable range for integer constants is ________?

    • A.

      -3.4e38 to 3.4e38

    • B.

      -32767 to 32768

    • C.

      -32668 to 32667

    • D.

      -32768 to 32767

    Correct Answer
    D. -32768 to 32767
    Explanation
    The correct answer is -32768 to 32767. This is because a 16-bit compiler can represent integers using 16 bits, which allows for a total of 2^16 = 65536 different values. However, one bit is used to represent the sign of the integer, leaving 15 bits to represent the magnitude. With 15 bits, the range of representable values is -2^15 to 2^15 - 1, which is equivalent to -32768 to 32767.

    Rate this question:

  • 29. 

    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

    Correct Answer
    C. Depends on the system/compiler
    Explanation
    The size of an int data type depends on the system or compiler being used. Different systems or compilers may allocate different amounts of memory for an int variable. Therefore, the size cannot be determined without considering the specific system or compiler in use.

    Rate this question:

  • 30. 

     What will be printed for the below statement?#include<stdio.h> main() { printf("%d",strcmp("strcmp()","strcmp()")); }

    • A.

      0

    • B.

      1

    • C.

      -1

    • D.

      Invalid use of strcmp() function

    Correct Answer
    A. 0
    Explanation
    The code is using the strcmp() function to compare two strings "strcmp()" and "strcmp()". The strcmp() function returns 0 if the two strings are equal. Therefore, the printf() statement will print 0.

    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 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Feb 13, 2017
    Quiz Created by
    Bug_quesh
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.