What is the syntax of pointer?

In C++, the syntax for declaring a pointer involves using the asterisk (*) symbol, which indicates that the variable being declared is a pointer to a particular data type. Below is the general syntax for pointer declaration:

Pointer Declaration Syntax:

data_type* pointer_name;

Examples:

  1. Pointer to an Integer:

    int* ptr; // Declares a pointer to an integer
  2. Pointer to a Float:

    float* fptr; // Declares a pointer to a float
  3. Pointer to a Character:

    char* cptr; // Declares a pointer to a char
  4. Pointer Initialization: Pointers can be initialized by assigning them the address of a variable using the address-of operator (&).

    int x = 5; int* ptr = &x; // ptr now holds the address of variable x
  5. Dereferencing a Pointer: You can access the value stored at the address pointed to by the pointer using the dereference operator (*).

    cout << *ptr; // Outputs the value of x, which is 5

Additional Notes:

  • Null Pointers: It is common practice to initialize pointers to nullptr to avoid dangling pointers.

    int* ptr = nullptr; // Initializes ptr to null
  • Pointer Arithmetic: You can perform arithmetic operations on pointers to navigate through arrays.

    int arr[3] = {10, 20, 30}; int* p = arr; // Points to the first element of the array p++; // Now p points to the second element (20)

Conclusion:

The basic syntax for pointers in C++ is straightforward, using the asterisk (*) to denote that a variable is a pointer. Understanding pointers is crucial for memory management, dynamic data structures, and efficient programming.

Sources:

TAGS
Coding Interview
CONTRIBUTOR
Design Gurus Team
-

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
Who answers Amazon questions?
What is the DP problem?
Why are technical interviews hard?
What are your weakness interview answers?
What is the highest paying internships hourly?
What is the fresher package in Atlassian?
Related Courses
Grokking the Coding Interview: Patterns for Coding Questions course cover
Grokking the Coding Interview: Patterns for Coding Questions
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
4.6
Discounted price for Your Region

$197

Grokking Modern AI Fundamentals course cover
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
3.9
Discounted price for Your Region

$72

Grokking Data Structures & Algorithms for Coding Interviews course cover
Grokking Data Structures & Algorithms for Coding Interviews
Unlock Coding Interview Success: Dive Deep into Data Structures and Algorithms.
4
Discounted price for Your Region

$78

Design Gurus logo
One-Stop Portal For Tech Interviews.
Copyright © 2026 Design Gurus, LLC. All rights reserved.