here also it doesnt wrk
2 posters
here also it doesnt wrk
cat fileone.c
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
int main( int argc, char* argv[])
{
char* buffer;
read(0,buffer,50);
printf("size is %d", sizeof buffer);
return 1;
}
[337480@oracleclient ~]$ gcc fileone.c -o nnn.out
[337480@oracleclient ~]$ ./nnn.out
thuiid kjkl
size is 8[337480@oracleclient ~]$
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
int main( int argc, char* argv[])
{
char* buffer;
read(0,buffer,50);
printf("size is %d", sizeof buffer);
return 1;
}
[337480@oracleclient ~]$ gcc fileone.c -o nnn.out
[337480@oracleclient ~]$ ./nnn.out
thuiid kjkl
size is 8[337480@oracleclient ~]$
SakeenaHarris- Posts : 7
Points : 13
Join date : 2010-03-08
Re: here also it doesnt wrk
hey i got the solution!
the size of char* datatype is 8 bytes!
so when ever we try to print the sizeof buffer we get the output as 8
now try printing the sizeof *buffer (buffer is pointer and * - Astrix before pointer gives the value of the location it point to!)
it will print 1 (which is the sizeof char datatype)
but when we try printing sizeof buffer[] we get the length of array! and not the size of char datatype (i.e. 1)
(pointer just points to a memory location! but array allocates a sequence of memory and creates a pointer which points to the first memory address in the sequence of allocated memory)
thats the difference between array and pointers
the size of char* datatype is 8 bytes!
so when ever we try to print the sizeof buffer we get the output as 8
now try printing the sizeof *buffer (buffer is pointer and * - Astrix before pointer gives the value of the location it point to!)
it will print 1 (which is the sizeof char datatype)
but when we try printing sizeof buffer[] we get the length of array! and not the size of char datatype (i.e. 1)
(pointer just points to a memory location! but array allocates a sequence of memory and creates a pointer which points to the first memory address in the sequence of allocated memory)
thats the difference between array and pointers
Permissions in this forum:
You cannot reply to topics in this forum
|
|