Home » C++ Quiz Questions

C++ | new and delete operators | question 2

What will be the output of the following program?

#include <iostream>
using namespace std;

int main() 
{
	int *ival = new int (10);
	
	cout<<ival<<endl;
	
	return 0;
}

(1) 10

(2) 0

(3) Memory address

(4) None of these

Answer: (3)

Explanation:

ival is a pointer variable, and to print the value through a pointer variable, we use asterisk character (*) with the pointer variable name.

Therefore, statement cout<<ival<<endl; will print the memory address.

To print its value, cout<<*ival<<endl; will be used.



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.