Quiz 5 - Functions And Pointers

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 Aamirakbar
A
Aamirakbar
Community Contributor
Quizzes Created: 1 | Total Attempts: 193
Questions: 10 | Attempts: 193

SettingsSettingsSettings
Quiz 5 - Functions And Pointers - Quiz


Class BEE-2A


Questions and Answers
  • 1. 

    Pointer is a special kind of a variable which is used to store _______ of a variable

    • A.

      Data Type

    • B.

      Value

    • C.

      Variable name

    • D.

      Address

    Correct Answer
    D. Address
    Explanation
    A pointer is a special kind of variable that is used to store the address of another variable. By storing the address, the pointer allows us to indirectly access and manipulate the value of the variable it points to. This is useful in situations where we need to pass variables by reference or dynamically allocate memory. Therefore, the correct answer is "address".

    Rate this question:

  • 2. 

    The operator used to declare a pointer variable is 

    • A.

      ^

    • B.

      %

    • C.

      *

    • D.

      &

    Correct Answer
    C. *
    Explanation
    The correct answer is * because in C and C++, the asterisk (*) symbol is used to declare a pointer variable. The asterisk is placed before the variable name to indicate that it is a pointer variable, which stores the memory address of another variable.

    Rate this question:

  • 3. 

    Variable passing by reference is achieved by using pointers.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Variable passing by reference is achieved by using pointers. In programming, passing by reference means that a reference to the original variable is passed to a function, allowing the function to directly modify the original variable. Pointers are used to achieve this behavior in many programming languages. By passing the memory address of a variable, the function can access and modify the original variable, rather than creating a copy. Therefore, the statement that variable passing by reference is achieved by using pointers is true.

    Rate this question:

  • 4. 

    Char data type uses _____ byte (s), int data type uses _____ byte (s) and float uses _____ byte (s)

    • A.

      2, 4, 1

    • B.

      4, 2, 1

    • C.

      1, 2, 4

    • D.

      4, 1, 2

    Correct Answer
    C. 1, 2, 4
    Explanation
    The correct answer is 1, 2, 4. The char data type uses 1 byte, the int data type uses 2 bytes, and the float data type uses 4 bytes.

    Rate this question:

  • 5. 

    Passing by value means an exact copy of the variable is created and the value is assigned to it.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Passing by value means that when a variable is passed as an argument to a function, a copy of the variable is created and the value of the original variable is assigned to it. This means that any changes made to the copy within the function will not affect the original variable. Therefore, the statement is true.

    Rate this question:

  • 6. 

    Choose the best answerPrior to using a pointer variable 

    • A.

      It should be declared

    • B.

      It should be initialized

    • C.

      It should be both declared and initialized

    • D.

      None of the above

    Correct Answer
    C. It should be both declared and initialized
    Explanation
    Prior to using a pointer variable, it is necessary to both declare and initialize it. Declaring a pointer variable means specifying its data type and name, while initializing it means assigning it a memory address to point to. If a pointer is not declared, it cannot be used in the program. Similarly, if it is not initialized, it does not have a valid memory address to point to, leading to potential errors or undefined behavior when trying to access the memory it points to. Therefore, both declaring and initializing a pointer variable are important steps before using it.

    Rate this question:

  • 7. 

    What does the following mean?int *ptr, p;

    • A.

      Ptr is a integer pointer, p is not

    • B.

      Both ptr and p are integer pointers

    • C.

      P may be a pointer but ptr is not

    • D.

      Both ptr and p are not pointers

    Correct Answer
    A. Ptr is a integer pointer, p is not
    Explanation
    This statement declares two variables, ptr and p. The declaration "int *ptr" means that ptr is a pointer to an integer. On the other hand, the declaration "p" does not have any asterisk (*) before it, indicating that it is not a pointer. Therefore, the correct answer is that ptr is an integer pointer, while p is not a pointer.

    Rate this question:

  • 8. 

    A pointer is

    • A.

      A keyword used to create variables

    • B.

      A variable that stores address of an instruction

    • C.

      A variable that stores address of other variable

    • D.

      All of the above

    Correct Answer
    C. A variable that stores address of other variable
    Explanation
    A pointer is a variable that stores the address of another variable. Pointers are used to indirectly access and manipulate data stored in memory. By storing the address of a variable, pointers allow for efficient memory management and the ability to pass variables by reference. Therefore, the correct answer is "A variable that stores the address of other variable."

    Rate this question:

  • 9. 

    #include<stdio.h>void f(){    printf("hello");}void main(){   f();}the code above has an error.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The code provided does not have any errors. It includes the necessary header file, defines a function "f()" that prints "hello", and calls the function "f()" in the main function. Therefore, the correct answer is False.

    Rate this question:

  • 10. 

    Suppose a variable x has  an address fff0. declaring a pointer and assigning address of x is as follow.int *p = &x;printf("address of x = %d", *p);the output will be [address of x = fff0] stored in pointer p?

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The output will not be "[address of x = fff0] stored in pointer p". The output will be the value stored at the address pointed to by pointer p, which is the value of variable x. In this case, it will be the address of x, not the value of x itself.

    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 30, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Nov 19, 2014
    Quiz Created by
    Aamirakbar
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.