If we declare a pointer like char *p;how much memory is allocated for pointer variable 'p'.

This question is related to TCS Interview

Questions by pavankishore   answers by pavankishore

Editorial / Best Answer

winny gupta  

  • Member Since Feb-2007 | Feb 15th, 2007


2 bytes of memory because the pointer variable, whatever data type it maybe pointing to is always an unsigned integer as the address is always a positive integer, hence requiring 2 bytes of memory

Showing Answers 1 - 75 of 90 Answers

Hema

  • Dec 1st, 2006
 

It will allocate two bytes of memory

winny gupta

  • Feb 15th, 2007
 

2 bytes of memory because the pointer variable, whatever data type it maybe pointing to is always an unsigned integer as the address is always a positive integer, hence requiring 2 bytes of memory

bhanu

  • Aug 24th, 2011
 

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. void main()

  4. {

  5. char *p;

  6. printf(" %d",*p);

  7. }

  8.  

  Was this answer useful?  Yes

janani

  • Aug 25th, 2011
 

thus 32 bits are allocated if we declare a char *p;

  Was this answer useful?  Yes

r.rubiya

  • Aug 26th, 2011
 

char2

  Was this answer useful?  Yes

Akshaya

  • Aug 27th, 2011
 

2 bytes

  Was this answer useful?  Yes

anusha

  • Aug 28th, 2011
 

Two bytes of memory

  Was this answer useful?  Yes

pooja

  • Aug 30th, 2011
 

1 byte

  Was this answer useful?  Yes

maggi

  • Sep 3rd, 2011
 

2 bytes

  Was this answer useful?  Yes

suman

  • Sep 3rd, 2011
 

*p means there is no certain amount of memory allocated for that it will take what data you give and there is no limitation like up to this size. There is no waste of memory.

  Was this answer useful?  Yes

navatha

  • Sep 7th, 2011
 

2

  Was this answer useful?  Yes

shafi

  • Sep 7th, 2011
 

depends on the data types....but this answer is 1 byte....

  Was this answer useful?  Yes

shiva

  • Sep 10th, 2011
 

1 byte

  Was this answer useful?  Yes

ronak

  • Sep 10th, 2011
 

2 bytes of memory will be allocated, as pointer always point to the unsigned integer as address are unsigned integer.

  Was this answer useful?  Yes

SHILPA

  • Sep 23rd, 2011
 

it will take 2 bytes. because pointer always take 2 bytes

  Was this answer useful?  Yes

anupama

  • Sep 25th, 2011
 

one byte

  Was this answer useful?  Yes

Avinash Chourasiya

  • Nov 12th, 2011
 

2 bytes

  Was this answer useful?  Yes

I know Ive answered this already, but I thought Id include a handy macro definition for getting the size of any type (pointer or otherwise) on your platform (see code insert). FWIW, here are the results on my system (Linux 2.4.20, gcc compiler in C99 mode):

Size of char = 1
Size of char * = 4
Size of unsigned char = 1
Size of unsigned char * = 4
Size of short = 2
Size of short * = 4
Size of unsigned short = 2
Size of unsigned short * = 4
Size of long = 4
Size of long * = 4
Size of unsigned long = 4
Size of unsigned long * = 4
Size of long long = 8
Size of long long * = 4
Size of unsigned long long = 8
Size of unsigned long long * = 4
Size of float = 4
Size of float * = 4
Size of double = 8
Size of double * = 4
Size of long double = 12
Size of long double * = 4
Size of struct {char a; char b; long y;} = 8
Size of struct {long y; char a; char b;} = 8
Size of struct {char a; char b; long y;} * = 4
Size of union {char a; char b; long y;} = 4
Size of union {char a; char b; long y;} * = 4

Code
  1. #include <stdio.h>

  2.  

  3. #if defined(__STDC__)

  4.   #if defined(__STDC_VERSION__)

  5.     #if __STDC_VERSION__ >= 199901L

  6.       #define C99 1

  7.     #endif

  8.   #endif

  9. #endif

  10.  

  11. #ifdef C99

  12.   #define fmt "%zu"

  13.   #define cast

  14. #else

  15.   #define fmt "%lu"

  16.   #define cast (unsigned long)

  17. #endif

  18.  

  19. #define PRINT_SIZE(t) printf("Size of %-30s = " fmt "

  20. ", #t, cast sizeof(t))

  21.  

  22. int main(void)

  23. {

  24.  PRINT_SIZE(char);

  25.  PRINT_SIZE(char *);

  26.  PRINT_SIZE(unsigned char);

  27.  PRINT_SIZE(unsigned char *);

  28.  PRINT_SIZE(short);

  29.  PRINT_SIZE(short *);

  30.  PRINT_SIZE(unsigned short);

  31.  PRINT_SIZE(unsigned short *);

  32.  PRINT_SIZE(long);

  33.  PRINT_SIZE(long *);

  34.  PRINT_SIZE(unsigned long);

  35.  PRINT_SIZE(unsigned long *);

  36. #ifdef C99

  37.  PRINT_SIZE(long long);

  38.  PRINT_SIZE(long long *);

  39.  PRINT_SIZE(unsigned long long);

  40.  PRINT_SIZE(unsigned long long *);

  41. #endif

  42.  PRINT_SIZE(float);

  43.  PRINT_SIZE(float *);

  44.  PRINT_SIZE(double);

  45.  PRINT_SIZE(double *);

  46. #ifdef C99

  47.  PRINT_SIZE(long double);

  48.  PRINT_SIZE(long double *);

  49. #endif

  50.  PRINT_SIZE(struct {char a; char b; long y;});

  51.  PRINT_SIZE(struct {long y; char a; char b;});

  52.  PRINT_SIZE(struct {char a; char b; long y;} *);

  53.  PRINT_SIZE(union {char a; char b; long y;});

  54.  PRINT_SIZE(union {char a; char b; long y;} *);

  55.  

  56.  return 0;

  57. }

  58.  

  Was this answer useful?  Yes

rasmita sahoo

  • May 17th, 2012
 

2 byte for tc & 4 byte for gcc compiler

  Was this answer useful?  Yes

reetu

  • Sep 30th, 2012
 

It allocate 2bytes in memory

  Was this answer useful?  Yes

Mukesh

  • Jan 20th, 2016
 

It depends on how much bit Turbo C software you are using. If it is 32 bit then it will take 4 byte. If it is 64 bit then pointer will take 8 bytes of memory. 

  Was this answer useful?  Yes

Alejandro

  • Mar 5th, 2016
 

It Depends on the architecture which is building on.
- In a 16-bit addressing system, 2 bytes.
- In a 32-bits addressing system 4 bytes.
- In a 64-bits addressing system 8 bytes.
Even in old architectures of 16-bits (80x286), depending if it was a far pointer it would size 32-bits (segment + offset).

  Was this answer useful?  Yes

Raees Ul Islam

  • Nov 25th, 2021
 

Pointer is actually is a reference to memory cell. In 32bit operating system, OS use 4 byte for pointing to any memory cell thats why only 4GB memory can be used in 32bit operating system. On the other hand a 64bit OS use 8byte for addressing.
So size of pointer depends upon OS, In 32bit OS pointer will take 4byte and in 64bit OS pointer will take 8 bytes.
No matter pointer is for char, int, bool, Structure it will remain same for all types

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions