GeekInterview.com
Series: Subject: Topic:
Question: 132 of 238

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

This question is related to TCS Interview
Asked by: pavankishore | Member Since Nov-2006 | Asked on: Nov 29th, 2006

View all questions by pavankishore   View all answers by pavankishore

Editorial / Best Answer

Answered by: winny gupta

View all answers by winny gupta

Member Since Feb-2007 | Answered On : 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 - 26 of 26 Answers
Hema

Answered On : Dec 1st, 2006

It will allocate two bytes of memory

Yes  3 Users have rated as useful.
  
Login to rate this answer.
winny gupta

Answered On : Feb 15th, 2007

View all answers by winny gupta

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

Yes  5 Users have rated as useful.
  
Login to rate this answer.
avula chiru

Answered On : Sep 30th, 2010

View all answers by avula chiru

int, float, or char any pointer variable takes 2bytes of memory..

Yes  1 User has rated as useful.
  
Login to rate this answer.
prititripathi

Answered On : Oct 1st, 2010

View all answers by prititripathi

it will take 2 bytes coz pointer store address which r of type int

Yes  1 User has rated as useful.
  
Login to rate this answer.
saurabh1341

Answered On : Oct 22nd, 2010

View all answers by saurabh1341

2 bytes.. because p will contain an address, which is 'int'

  
Login to rate this answer.
prititripathi

Answered On : Dec 18th, 2010

View all answers by prititripathi

pointer store address so it will require 2 byte

  
Login to rate this answer.
jbode

Answered On : Aug 23rd, 2011

View all answers by jbode

The answer will vary by platform. It could be as little as 2 bytes or more than 8. On the systems I work with, it's typically 4 bytes.

  
Login to rate this answer.
bhanu

Answered On : 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.  

  
Login to rate this answer.
janani

Answered On : Aug 25th, 2011

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

  
Login to rate this answer.
r.rubiya

Answered On : Aug 26th, 2011

char2

  
Login to rate this answer.
Akshaya

Answered On : Aug 27th, 2011

2 bytes

  
Login to rate this answer.
anusha

Answered On : Aug 28th, 2011

Two bytes of memory

  
Login to rate this answer.
pooja

Answered On : Aug 30th, 2011

1 byte

  
Login to rate this answer.

& address is of the type integer, it can't be a character or a float.
& Integer takes two bytes to store So answer would be 2bytes.

  
Login to rate this answer.
maggi

Answered On : Sep 3rd, 2011

2 bytes

  
Login to rate this answer.
suman

Answered On : 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.

  
Login to rate this answer.
navatha

Answered On : Sep 7th, 2011

2

  
Login to rate this answer.
shafi

Answered On : Sep 7th, 2011

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

  
Login to rate this answer.
shiva

Answered On : Sep 10th, 2011

1 byte

  
Login to rate this answer.
ronak

Answered On : Sep 10th, 2011

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

  
Login to rate this answer.
SHILPA

Answered On : Sep 23rd, 2011

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

  
Login to rate this answer.
anupama

Answered On : Sep 25th, 2011

one byte

  
Login to rate this answer.
Avinash Chourasiya

Answered On : Nov 12th, 2011

2 bytes

  
Login to rate this answer.
jbode

Answered On : Jan 18th, 2012

View all answers by jbode

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.  

  
Login to rate this answer.
rasmita sahoo

Answered On : May 17th, 2012

2 byte for tc & 4 byte for gcc compiler

  
Login to rate this answer.
reetu

Answered On : Sep 30th, 2012

It allocate 2bytes in memory

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.