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
Arslan Ahmad
Arslan Ahmad
ex-FAANG engineering manager and author or Grokking series.
-

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
What are the skills required to join IBM?
Which strategy does Netflix use?
Why do you want to join Google?
What is difficult in software engineering?
Which frontend framework is best for beginners?
What skills are needed for a backend developer?
Related Courses
New
Grokking the AI System Design Interview course cover
Grokking the AI System Design Interview
Learn to design AI systems the way interviewers expect: classic ML products, LLM and RAG architectures, and agentic systems, all through the lens of the system design interview.
4.8
(1,192 learners)
Discounted price for Your Region

$123

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.
4.1
Discounted price for Your Region

$72

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