
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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 Articles
- A C/C++ Pointer Puzzle?
- C/C++ Function Call Puzzle?
- Double Pointer (Pointer to Pointer) in C
- A C Puzzle in C Programming?
- A C/C++ Function Call Puzzle?
- C++ Sum Array Puzzle
- Sliding Puzzle in C++
- Pointer Arithmetic in C/C++
- A Puzzle using C Program
- A C Programming Language Puzzle?
- Verbal Arithmetic Puzzle in C++
- A Puzzle on C/C++ R-Value Expressions?
- NULL pointer in C
- void pointer in C
- Function Pointer in C

Advertisements