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

Hours before exams
It is advisable not to read new topics before any exam . Proper rest is important along with proper food . In order to avoid last minute rush, it is always best to maintain notes which should be precise and written of their own. Revision is a must .

Memory Layout in C++ vis-a-vis Polymorphism and Padding bits.
I know there is no need for the knowledge of memory layout for a normal day-to-day development of C++. However, when someone goes in the bit/byte level of C++, he needs to look for such discussion. To...

Shell Scripting - The underrated programming language of system administrators
It is oft repeated that the next wave of IT is automation. But automation is not new - it existed before in terms of automated installation, sending birthday mails etc. It was not untill you actually...

Income Under The Head Salary
SALARY Relationship of the receiver with payer: Income under head salary is taxable only if there is employer, employee relationship between payer and payee. And this relation is said to exist only if...
F

Networking Basic
Networking interview questionsWhat is LAN?LAN is a computer network that spans a relatively small area. Most LANs are confined to a single building or group of buildings. However, one LAN can be connected...
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