What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
char *ptr;
char Str[] = “abcdefg”;
ptr = Str;
ptr += 5;
cout << ptr;
return 0;
}
a) fg
b) cdef
c) defg
d) abcd
Answer: a
Explanation: Pointer ptr points to string ‘fg’. So it prints fg.
Output:
fg
Related Posts
What we can’t do on a void pointer?
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int a = 5, c;
void *p = & a;
double b = 3.14;
p = & b;
c = a + b;
cout << c << ‘\n’ << p;
return 0;
}What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int n = 5;
void *p = & n;
int *pi = static_cast< int*>(p);
cout << *pi << endl; return 0; }What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int i;
char c;
void *data;
i = 2;
c = ‘d’;
data = & i;
cout << “the data points to the integer value” << data;
data = & c;
cout << “the data now points to the character” << data;
return 0;
}What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int *p;
void *vp;
if (vp == p);
cout << “equal”;
return 0;
}What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int func(void *Ptr);
int main()
{
char *Str = “abcdefghij”;
func(Str);
return 0;
}
int func(void *Ptr)
{
cout << Ptr;
return 0;
}A void pointer cannot point to which of these?
Join The Discussion