
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C/C++ Pointer Puzzle?
A Pointer is a variable that stores the address of another variable. The data type of the pointer is the same as the data type as the variable.
In this puzzle you need to know the size of the pointer that is being used. The puzzle checks our understanding of pointers by asking you the size of variable.
The size of int is 4 bytes, whereas the size of int pointer is 8. Now, let’s test your skills with the following exercise in c++ programming language.
Example
#include <iostream> using namespace std; int main() { int a = 6 ; int *p = &a; int arr[5][8][3]; int *q = &arr[0][0][0]; int ans; cout<<"the value of a is "<<a<<endl; cout<<"predict the size of a "; cin>> ans; if(ans == sizeof(p)) { cout<<"Hurry! your prediction is right"; } else { cout<<"Your Guess is wrong "; } cout<<"Now try this "<<endl; cout<<"arr is a 3D array"<<endl; cout<<"predict the size of arr "; cin>> ans; if(ans == sizeof(q)) { cout<<"Hurry! your prediction is right"; } else { cout<<"Your Guess is wrong "; } return 0; }
Output
the value of a is 6 predict the size of a 8 Hurry! your prediction is right Now try this arr is a 3D array predict the size of arr 4 Your guess is wrong
- Related Questions & Answers
- A C/C++ Pointer Puzzle?
- C/C++ Function Call Puzzle?
- C++ Sum Array Puzzle
- Sliding Puzzle in C++
- Double Pointer (Pointer to Pointer) in C
- A C/C++ Function Call Puzzle?
- A C Puzzle in C Programming?
- A C Programming Language Puzzle?
- A Puzzle using C Program
- Verbal Arithmetic Puzzle in C++
- Pointer Arithmetic in C/C++
- A Puzzle on C/C++ R-Value Expressions?
- A Product Array Puzzle in C++?
- A Sum Array Puzzle in C++?
- A Boolean Array Puzzle in C?
Advertisements