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);
char p = *malloc(100);
char *p = (char) malloc(100);
char *p = (char*)malloc(100);
char *p = (char *)(malloc*)(100);
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
82 comments Page 3 of 9.

Abhijit kamune said:   1 decade ago
Hey tell me where actually memory get allocate when we use malloc(), or calloc().

What is main diff between malloc() and calloc() ?

Prasath said:   1 decade ago
1) All memories allocated by memory management API's like malloc and calloc will be allocated from the Heap partition of the program.

2) Both malloc and calloc will allocate memories but, malloc just allocate required memory leaving the garbage value as it is but calloc allocate memory required and clear it with 0.

Krishna said:   1 decade ago
Can you combine two statements in pointers.

Krishna said:   1 decade ago
Can you explain pointe def and array def.

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.

Fousiya said:   1 decade ago
Thanks Kavyasri

Divya said:   1 decade ago
Thanx kavyasree & mahesh........

Devi said:   1 decade ago
I want difference for pointer in c and c++?

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.

Shailesh said:   1 decade ago
Please explain why we use a pointer.

With real time example.

Plz?


Post your comments here:

Your comments will be displayed after verification.