C++ Programming MCQ - Pointers
11. What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
int x = 1, y = 3, z = 5;
int *lfc[ ] = {&x, &y, &z};
cout << lfc[1];
return 0;
}
View Answer
12. What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
char lfc[20];
int i;
for(i = 0; i < 10; i++)
*(lfc + i) = 65 + i;
*(lfc + i) = ' ';
cout << lfc;
return(0);
}
View Answer
13. 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;
}
View Answer
14. Which of the following statement is correct about the program given below?
Note:Includes all required header files
using namespace std;
int main()
{
int a[2][4] = {1, 2, 3, 4, 5, 6, 7, 8};
cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];
return 0;
}
View Answer
15. Which of the following is true about the following program
#include <iostream>
using namespace std;
int main()
{
int i;
char *lfc[] = {"C", "C++", "Java", "VBA"};
char *(*ptr)[4] = &lfc;
cout << ++(*ptr)[2];
return 0;
}
View Answer
16. What will be the output of this program?
Note:Includes all required header files
using namespace std;
int main()
{
int find[] = {1, 2, 3, 4};
int *p = (find + 1);
cout << *p;
return 0;
}
View Answer
17. What will be the output of this program?
Note:Includes all required header files
using namespace std;
int main()
{
int find[] = {1, 2, 3, 4};
int *p = (find + 1);
cout << find;
return 0;
}
View Answer
18. What will be the output of the following program?
Note:Includes all required header files
using namespace std;
int main()
{
int find[] = {1, 2, 3, 4};
int *p = (find + 1);
cout << *find + 9;
return 0;
}
View Answer
19. What will be the output of the following program?
Note:Includes all required header files
using namespace std;
int main ()
{
int find[5];
int * p;
p = find; *p = 1;
p++; *p = 2;
p = &find[2]; *p = 3;
p = find + 3; *p = 4;
p = find; *(p + 4) = 5;
for (int n = 0; n < 5; n++)
cout << find[n] << ",";
return 0;
}
View Answer
20. The correct statement for a function that takes pointer to a float, a pointer to a pointer to a char and returns a pointer to a pointer to a integer is
View Answer
Also check :