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

Lingarajathi said:   1 decade ago
Hello Mr/Ms

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

Mahesh said:   1 decade ago
Here we have to allocate space for characters.so first we have to do typecasting i.e (char *).

If we give (char) it gives error because we are using pointer, then we allocate memory space by malloc().

Tj015 said:   1 decade ago
Online complier great, can somebody tell me what are the prerequisite for making online complier.

Chinna said:   1 decade ago
If there is allocated space in char p.

Chandana said:   1 decade ago
Thanks mahesh.

Nagarajan said:   1 decade ago
I want clear details from pointers with example.

Kavyashree said:   1 decade ago
Prototype of malloc is

  ptr = (data type *)malloc(size);
  - where ptr is pointer of type datatype.

So in the above example as we need to allocate memory for char it can be done with the following statement:

  char *p = (char*)malloc(1000); // here p is a pointer of type char

Vikrant said:   1 decade ago
Thanks Kavyashree. Yours explanation was good.

Mohan said:   1 decade ago
Actually we use pointer for p, then why we need another pointer for the location.

Arunpandiyan said:   1 decade ago
This about nothing but Initialization and declaration of varibale present on same line ,.
Well char c;
c='a';
can be written as char c = 'a';
the same we applied here a pointer value can can be assigned only to pointer variable, char *p=(char *)malloc(1000)


Post your comments here:

Your comments will be displayed after verification.