Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
clear me plz. bcoz if pointer holds an adress so doesnot matter it is the adress of char , int or float.
Posted
Comments
Afzaal Ahmad Zeeshan 12-Jan-16 3:08am    
Pointer to a char, means that it is a pointer to a value of character type. Pointer are usually integer type (because address is a hexadecimal value).

It matters because of pointer arithmetic (see, for instance "C++ pointer arithmetic"[^]). Try:
C
#include <stdio.h>

int main()
{
  double d = 5.0;
  double * pd;
  char * pc;

  pd = &d;
  pc = (char *) &d;

  printf("pd = %p, pc = %p\n", pd, pc); // same address, here
  ++pd;
  ++pc;
  printf("pd = %p, pc = %p\n", pd, pc); // OOOPS!

  return 0;
}
 
Share this answer
 
v3
Comments
Afzaal Ahmad Zeeshan 12-Jan-16 3:08am    
Good point, you've raised. 5ed.
CPallini 12-Jan-16 3:12am    
Thank you.
Whenever you reference a memory address, you have to decide how to interpret the data you find there, that's the meaning of the pointer-type, and type at all...
(There are languages where you do not define type and the environment will decide for you how to interpret that type - with occasional errors)
You should read here: Pointers - C++ Tutorials[^]
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 12-Jan-16 3:08am    
5ed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900