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 4 of 9.
Arunsudharsan said:
1 decade ago
main(){
int i=320;
for(int j=1;j<=i-1;j++)
{
char *ptr=(char*)&j;
printf("%d\n",*ptr);
}
return 0;
}
You will get a clear idea @Sivakumar.
int i=320;
for(int j=1;j<=i-1;j++)
{
char *ptr=(char*)&j;
printf("%d\n",*ptr);
}
return 0;
}
You will get a clear idea @Sivakumar.
Chandan said:
1 decade ago
Thanks to all for discussion. But one think *P and pointer without star, both are different one store value and other store address then how you combine?
Subha said:
1 decade ago
If p is a pointer.
i.e. p addressing some variable for eg x.
The p stores the address of x.
And *p gives the value of x. Is this correct or not?
i.e. p addressing some variable for eg x.
The p stores the address of x.
And *p gives the value of x. Is this correct or not?
Pratik Dutta said:
9 years ago
We can variable declare as int i;
I=10;
Int i=10;
At first we declare the variable then assign value, but together we can write the last line.
I=10;
Int i=10;
At first we declare the variable then assign value, but together we can write the last line.
Rafael Bluhm said:
1 decade ago
Is not correct to cast*void types in C. Malloc returns a void pointer, and compiles cast it automatically.
The correct is char*p = malloc(100);
The correct is char*p = malloc(100);
Vijay said:
8 years ago
step 1: char p // It is normal.
step 2: here we are using pointer so p = p* and p = 1000(size).
step 3 : P* = (char*)malloc(1000).
step 2: here we are using pointer so p = p* and p = 1000(size).
step 3 : P* = (char*)malloc(1000).
Vasu said:
1 decade ago
In char *p ,
char p = (char*) malloc (100);
(or)
char p = (char*) malloc (100);
Wheteher we are allocating 100 bytes for p or *p?
char p = (char*) malloc (100);
(or)
char p = (char*) malloc (100);
Wheteher we are allocating 100 bytes for p or *p?
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() ?
What is main diff between malloc() and calloc() ?
Parth lathiya said:
3 years ago
@Vij.
Both are not the same.
Because
1) not a proper variable pointer declaration.
So, 2) proper define the pointer variable.
Both are not the same.
Because
1) not a proper variable pointer declaration.
So, 2) proper define the pointer variable.
Jeevanantham said:
1 decade ago
The malloc() function is a memory allocation type. It allocats memory in bytes and also return the pointer to allocated memory.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers