If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?
1 Crore+ students have signed up on EduRev. Have you? Download the App |
Predict the output of following C++ program.
#include<iostream>
using namespace std;
class Test
{
private:
int x;
public:
Test(int x = 0) { this->x = x; }
void change(Test *t) { this = t; }
void print() { cout << "x = " << x << endl; }
};
int main()
{
Test obj(5);
Test *ptr = new Test (10);
obj.change(ptr);
obj.print();
return 0;
}
Which one of the following is not a possible state for a pointer?
What is the output of this program?
#include < iostream >
using namespace std;
int main()
{
int a = 5, b = 10, c = 15;
int *arr[ ] = {&a, &b, &c};
cout << arr[1];
return 0;
}
What will be the output of the following program code?
#include<stdio.h>
int main()
{
int i = 10;
void *p = &i;
printf("%f\n", *(float *)p);
return 0;
}
Predict the output of following C++ program?
#include<iostream>
using namespace std;
class Test
{
private:
int x;
public:
Test() {x = 0;}
void destroy() { delete this; }
void print() { cout << "x = " << x; }
};
int main()
{
Test obj;
obj.destroy();
obj.print();
return 0;
}
What is the output of this program?
#include < iostream >
using namespace std;
int main()
{
char *ptr;
char Str[] = "abcdefg";
ptr = Str;
ptr += 5;
cout << ptr;
return 0;
}