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 8 of 9.
Madhureddy said:
1 decade ago
Kavyashree explanation was excellent.
Rashmi said:
1 decade ago
Here malloc (100) give the address and then by char*malloc (100) we got the value that is placed on that address.
And now we assign that value to char p* by that we get a pointer of char type.
And now we assign that value to char p* by that we get a pointer of char type.
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)
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)
Mohan said:
1 decade ago
Actually we use pointer for p, then why we need another pointer for the location.
Vikrant said:
1 decade ago
Thanks Kavyashree. Yours explanation was good.
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
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
Nagarajan said:
2 decades ago
I want clear details from pointers with example.
Chandana said:
2 decades ago
Thanks mahesh.
Chinna said:
2 decades ago
If there is allocated space in char p.
Tj015 said:
2 decades ago
Online complier great, can somebody tell me what are the prerequisite for making online complier.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers