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 2 of 9.
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?
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 ?
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 ?
Umashankar Singh said:
1 decade ago
Please can an one explain malloc and calloc function ?
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.
Priya said:
1 decade ago
Can anybody explain where is the pointer use, what is the purpose using of pointer?
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.
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.
Parsam sai bharath said:
1 decade ago
Actually return type of malloc() or calloc() void pointer. So should typecast it.
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?
Sabarno said:
1 decade ago
Say: int a=10;
// This means a is a variable where 10 is stored.
Now say the address/ memory location of a is 5000.
So, I say: int *a= 5000;
// 5000 refers to the memory location of a or pointed to a.
Hence
For storing a value you need a definition statement and for storing a memory address you need a pointer.
// This means a is a variable where 10 is stored.
Now say the address/ memory location of a is 5000.
So, I say: int *a= 5000;
// 5000 refers to the memory location of a or pointed to a.
Hence
For storing a value you need a definition statement and for storing a memory address you need a pointer.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers