UrbanPro
true

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Why do pointers have a datatype?

Before we start with pointers you must know what is a variable and a datatype.

int a;

This is the basic line in every program in 'C' . It means that we are asking the compiler to give us 2 bytes of space in memory and label that space as 'a'.

Now every block of memory has an address(the variable names are only to make our work easy. imagine remembering xx000345= x230989+xx0044563 instead of C= A+ B;)

This addresses can also be stored in variable and that variable is aclled pointer.

so pointers are variable storing the address of another variable.

int* b; means that "b" is going to store the address of a variable whose datatype is "int".

b=&a; // now b points to a;

Have you ever thought why do we need a datatype for a pointer even though it doesn't store a value.??

The Data type is needed when dereferencing the pointer so it knows how much data it should read. For example dereferencing a chart pointer should read the next byte from the adress it is pointing to while an int pointer should read 2 bytes.

Now what do we mean by dereferncing?

Dereferencing a pointer means getting the value that is stored in the memory location pointed by the pointer. The operator * is used to do this, and is called the dereferencing operator.

There is a lot to be discussed in pointers. like pointer to pointer, pointer arithmetic, pointer to function, object, structure array, constant pointer etc.

 We shall do that in series to follow.

0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

Understanding Big Omega (?), Big Theta (?), Small Oh (o) And Small Omega (?) Notations
How to describe Big Omega(Ω) ? If run time of an algorithm is of Ω(g(n)), it means that the running time of the algorithm (as n gets larger) is at least proportional to g(n). Hence it helps...

Basics Of C And C++
C++ is powerful, highly flexible, and adaptable programming language that allows software engineers to organise and process information quickly and effectively. But this high-level language is relatively...

Trigonometric Formulas
Important Trigonometric Formulas:
K

Scope Of BCA After 12th Standard
In this article, we will have an in-depth analysis of the course named BCA. BCA. stands for Bachelor of Computer Applications. We will check out basic course details, course duration, important subjects...

Static and dynamic libraries
A library is a package of code that is meant to be reused by many programs. A static library (also known as an archive) consists of routines that are compiled and linked directly into your program. When...
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more