C Programming - Pointers - Discussion
Discussion Forum : Pointers - General Questions (Q.No. 2)
2.
Can you combine the following two statements into one?
char *p;
p = (char*) malloc(100);
Discussion:
82 comments Page 6 of 9.
Rahul roy said:
1 decade ago
Because pointer indicate the address and point out that point. So the char*p indicate that point p.
Prasanth said:
1 decade ago
Thanks kavya
Shailesh said:
1 decade ago
Please explain why we use a pointer.
With real time example.
Plz?
With real time example.
Plz?
Ravi said:
1 decade ago
The work of malloc function----->
> Malloc function allocate a fixed size block of memory from the heap and retuns a void type of pointer to it.
> Now we wont to store char type value in that memory so we have to convert the void type pointer to char type that's why (char *) is used to typecast the void pointer to char type.
The diff. between malloc and calloc------->
> syntaxt : data-type *p=(data-type *)malloc(size_t size);
> Malloc function allocates the a fixe size block of memory from the heap.
>syntaxt : data-type *p=(data-type *)calloc(size_t nsize,size_t size);
>Calloc function allocates the a size of (nsize *size) variable size block of memory from the heap.
> Malloc function allocate a fixed size block of memory from the heap and retuns a void type of pointer to it.
> Now we wont to store char type value in that memory so we have to convert the void type pointer to char type that's why (char *) is used to typecast the void pointer to char type.
The diff. between malloc and calloc------->
> syntaxt : data-type *p=(data-type *)malloc(size_t size);
> Malloc function allocates the a fixe size block of memory from the heap.
>syntaxt : data-type *p=(data-type *)calloc(size_t nsize,size_t size);
>Calloc function allocates the a size of (nsize *size) variable size block of memory from the heap.
Devi said:
1 decade ago
I want difference for pointer in c and c++?
Divya said:
1 decade ago
Thanx kavyasree & mahesh........
Fousiya said:
1 decade ago
Thanks Kavyasri
ILYAS said:
1 decade ago
Its very much simple many people have discussed in a lengthy way:
Understand 1st statement char*p, it means it stores the address of p let us its address is 1000. It means 1000---->p, clearly hear 1000 is pointing p, i.e char*p= p.
Replace p as char *p.
Understand 1st statement char*p, it means it stores the address of p let us its address is 1000. It means 1000---->p, clearly hear 1000 is pointing p, i.e char*p= p.
Replace p as char *p.
Krishna said:
1 decade ago
Can you explain pointe def and array def.
Krishna said:
1 decade ago
Can you combine two statements in pointers.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers