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

Divisibility rule
Every no. Is divisible by 1. Every even no. Is divisible by 2. If the sum of digit of a no. Is divisible by 3 then the no. Is also divisible by 3. If the last two digit is divisible by 4 then that no....
M

Mohit S.

1 0
0

MATHS IS EASY
Mathematics is based on formulas and method to use them.The practice make you perfect in this subject. Prepare according to syllabus, try to solve old papers, revise the concept you learned and try to...
M

Mohit S.

1 0
0

A Tutorial On Dynamic Programming
What is Dynamic Programming? Dynamic Programming, DP in short, is an intelligent way of solving a special type of complex problems which otherwise would hardly be solved in realistic time frame. What...

How to learn or method of learning?
Friends,Now we will see what is learning definately you may feel that is this a question. we know very well becuase we already gone through that process i.e schools & college. But again i want to focus...
S

Malware
Malware Vivek like any other teenage boy loves to play online games on his phone. He usually downloads the free games available at the trusted market zones. One day, he got an SMS “Click...
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