Knowee
Questions
Features
Study Tools

Single File Programming QuestionProblem StatementSharon wants to create a program that declares and initializes pointers of various types (void, integer, character, and float) and prints their sizes using the sizeof operator.Assist Sharon in achieving the task.Input format :No console input.Output format :The first line of output displays "Void Pointer = " followed by the size of the void pointer.The second line displays "Integer Pointer = " followed by the size of the integer pointer.The third line displays "Character Pointer = " followed by the size of the character pointer.The fourth line displays "Float Pointer = " followed by the size of the float pointer.Refer to the sample output for formatting specifications.Sample test cases :Input 1 :Output 1 :Void Pointer = 8Integer Pointer = 8Character Pointer = 8Float Pointer = 8Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.Marks : 10Negative Marks : 0WhitelistSet 1:*

Question

Single File Programming QuestionProblem StatementSharon wants to create a program that declares and initializes pointers of various types (void, integer, character, and float) and prints their sizes using the sizeof operator.Assist Sharon in achieving the task.Input format :No console input.Output format :The first line of output displays "Void Pointer = " followed by the size of the void pointer.The second line displays "Integer Pointer = " followed by the size of the integer pointer.The third line displays "Character Pointer = " followed by the size of the character pointer.The fourth line displays "Float Pointer = " followed by the size of the float pointer.Refer to the sample output for formatting specifications.Sample test cases :Input 1 :Output 1 :Void Pointer = 8Integer Pointer = 8Character Pointer = 8Float Pointer = 8Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.Marks : 10Negative Marks : 0WhitelistSet 1:*

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple C++ program that declares and initializes pointers of various types and prints their sizes using the sizeof operator.

#include<iostream>
using namespace std;

int main() {
    // Declare and initialize pointers
    void *voidPointer;
    int *intPointer;
    char *charPointer;
    float *floatPointer;

    // Print sizes of pointers
    cout << "Void Pointer = " << sizeof(voidPointer) << endl;
    cout << "Integer Pointer = " << sizeof(intPointer) << endl;
    cout << "Character Pointer = " << sizeof(charPointer) << endl;
    cout << "Float Pointer = " << sizeof(floatPointer) << endl;

    return 0;
}

This program first includes the necessary header files. Then, in the main function, it declares and initializes pointers of various types: void, integer, character, and float. After that, it uses the sizeof operator to print the sizes of these pointers. The sizeof operator returns the size (in bytes) of the object or type. The output of this program will depend on the system where it is run, as the size of pointers can vary between systems.

This problem has been solved

Similar Questions

Single File Programming QuestionProblem Statement Baljith is developing a program that uses a void pointer to store the addresses of integer and float variables and needs your assistance in completing it. First, get two values (an integer and a float) from the user. Then, perform type casting to retrieve and display the values.Input format :The first line of input consists of an integer value N.The second line consists of a floating-point value F.Output format :The first line of output displays "Integer = " followed by the integer value.The second line displays "Float = " followed by the floating-point value, with two decimal places.Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ N ≤ 5501.0 ≤ F ≤ 150.0Sample test cases :Input 1 :12620.25Output 1 :Integer = 126Float = 20.25Input 2 :535149.7Output 2 :Integer = 535Float = 149.70

Single File Programming QuestionProblem StatementAman is assigned a program that takes a generic pointer (void *) to handle different data types. You have to guide him in completing the program.The program prompts the user to input a data type identifier ('i' for integer, 'f' for float) and a corresponding value. Using a switch statement, print the entered value with the appropriate data type label. Any other input except ('i' and 'f') is given, print "Invalid type entered!" Input format :The first line of input consists of a character, representing a data type (i for integer or f for float).If the character is i, the second line consists of an integer value.If the character is f, the second line consists of a floating-point value.Output format :If the character is i, print "Integer: " followed by the integer value.If the character is f, print "Float: " followed by the float value, rounded off to two decimal places.If any other character is entered, print "Invalid type entered!"Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ integer ≤ 1501.0 ≤ float ≤ 150.0Sample test cases :Input 1 :i4Output 1 :Integer: 4Input 2 :f5.5Output 2 :Float: 5.50Input 3 :p50Output 3 :Invalid type entered!Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Single File Programming QuestionProblem StatementArun is developing a program that demonstrates the use of a constant pointer to a constant integer (const int *). He should take an integer input from the user, use a constant pointer to store its address, and then print both the original value of the integer and the value accessed through the constant pointer.Guide Arun to accomplish the task.Input format :The input consists of an integer.Output format :The first line of output prints "Original value of number: ", followed by the input integer.The second line prints "Value accessed through const pointer: ", followed by the value accessed through the pointer.Refer to the sample output for formatting specifications.Sample test cases :Input 1 :10Output 1 :Original value of number: 10Value accessed through const pointer: 10Input 2 :89Output 2 :Original value of number: 89Value accessed through const

Suppose that in a C program snippet, followings statements are used.i) sizeof(int);ii) sizeof(int*);iii) sizeof(int**);

Single File Programming QuestionProblem StatementJohn is eager to create a simple program for gathering and presenting personal details. Write a program that prompts users to provide the initial letter of their name (a character), age (an integer), and height in meters (a floating-point number).After collecting this information, display it in a well-organized format.Input format :The input consists of three space-separated values, representing the first letter of the name (character), age (integer), and height in meters (floating point value), separated by spaces.Output format :The first line prints the initial of the name in the format "Initial: [initial]"The second line prints the age in the format "Age: [age] years"The third line prints the height of the person, rounded to two decimal places, in the format "Height: [height] meters"Refer to the sample output for formatting specifications.Code constraints :In the given scenario, the test cases will fall under the following constraints:10 ≤ Age ≤ 500.01 ≤ Height ≤ 1.80Sample test cases :Input 1 :A 10 1.35Output 1 :Initial: AAge: 10 yearsHeight: 1.35 metersInput 2 :b 25 1.70Output 2 :Initial: bAge: 25 yearsHeight: 1.70 metersInput 3 :Z 28 1.80Output 3 :Initial: ZAge: 28 yearsHeight: 1.80 metersCode Size : 1024 kbNote :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.Marks : 10Negative Marks : 0

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.