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.

Katty said:   1 decade ago
The space is allotted for pointers.

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);

Appala prathyusha said:   1 decade ago
How do we know the address of i?

Sandeep said:   1 decade ago
#include<stdio.h>
int main(){
int i=320;
char *ptr=(char*)&i;
printf("%d",*ptr);
return 0;
}

The answer is 64 because it will take will only first 8 bits from 16 bits of int.

Sudhagar said:   1 decade ago
I need more explanation about pointers?

Shabana said:   1 decade ago
#include<stdio.h>
int main(){
int i=320;
char *ptr=(char*)&i;
printf("%d",*ptr);
return 0;
}

Output is: 64;

How can any one explain these please I didn't understand?

Mahes said:   1 decade ago
I want clear details in pointer?why we use this concept?

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?

Yadhanna said:   1 decade ago
In char *p ,
char p = (char*) malloc (100);

we are allocating 100bytes for a pointer variable "p". What is the need for that ? Are we storing 100 addresses ?

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.


Post your comments here:

Your comments will be displayed after verification.