Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is pointer declaration in C?

Syed Muhammad Ali Mustafa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

Pointer is a special datatype that stores the address of a memory location in C.

Declaration

[datatype] *[var_name];

Example

Following is an example of the declaration, where int denotes that it is an integer pointer and ptr is the name of the variable:

int *ptr;

Key points

  1. Pointers should point to variables of the same datatype. The following statement is not allowed in C:
char ch;
double *ptr = &ch; //type mismatch error
  1. A pointer that is assigned a NULL value is called a NULL pointer.
float *ptr = NULL;

Code

#include<stdio.h>
int main() {
int x = 5;
int *ptr = &x;
//dereferencing the pointer variable ptr with asterisk
printf("%d", *ptr);
return 0;
}

RELATED TAGS

c

CONTRIBUTOR

Syed Muhammad Ali Mustafa
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring