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 8 of 9.

Paramjeet singh said:   1 decade ago
First of all malloc is memory data type and p is character pointer data type. So as we know comparison is possible between two same entity so we will cast malloc as character pointer then equate at character pointer p.

Venkata surendra said:   1 decade ago
The difference between c and c++ pointer is only one thing
c pointer is suspicious pointer nothing but a pointer variable which holds address un related type...
simple example
int x=10;
float *p;
p=&x;// it leads to logical error but c complier doesnt give any error same program if you save.cpp extension error will occur.

Lingarajathi said:   2 decades ago
Hello Mr/Ms

I need clear details about pointers and pointers memory allocation, can you send me this me the details.

Prasanth said:   1 decade ago
Thanks kavya

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

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.

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.


Post your comments here:

Your comments will be displayed after verification.