IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C# Programming Java Programming
Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET

C Programming - Pointers - Discussion

@ : Home > C Programming > Pointers > General Questions - Discussion

2. 

Can you combine the following two statements into one?

char *p;
p = (char*) malloc(100);

[A]. char p = *malloc(100);
[B]. char *p = (char) malloc(100);
[C]. char *p = (char*)malloc(100);
[D]. char *p = (char *)(malloc*)(100);

Answer: Option B

Explanation:

No answer description available for this question.


Lingarajathi said: (Sun, Jun 20, 2010 11:44:27 PM)    
 
Hello Mr/Ms

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

Mahesh said: (Wed, Jul 7, 2010 02:39:49 AM)    
 
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: (Wed, Jul 7, 2010 08:36:23 AM)    
 
Online complier great, can somebody tell me what are the prerequisite for making online complier.

Chinna said: (Tue, Jul 20, 2010 08:23:36 PM)    
 
If there is allocated space in char p.

Chandana said: (Thu, Jul 29, 2010 10:15:47 AM)    
 
Thanks mahesh.

Nagarajan said: (Tue, Aug 24, 2010 05:13:24 AM)    
 
I want clear details from pointers with example.

Kavyashree said: (Sun, Oct 10, 2010 11:28:03 AM)    
 
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: (Mon, Oct 11, 2010 02:03:53 AM)    
 
Thanks Kavyashree. Yours explanation was good.

Mohan said: (Sun, Dec 26, 2010 12:38:30 PM)    
 
Actually we use pointer for p, then why we need another pointer for the location.

Arunpandiyan said: (Fri, Jan 7, 2011 02:38:39 PM)    
 
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)

Rashmi said: (Thu, Jan 13, 2011 04:37:52 AM)    
 
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.

Madhureddy said: (Sun, Jan 30, 2011 09:54:47 AM)    
 
Kavyashree explanation was excellent.

Suma Sahithi said: (Mon, Jan 31, 2011 10:28:48 PM)    
 
Thanks Mahesh and Kavyasri for the explanation.

Saran said: (Thu, Feb 3, 2011 06:51:10 AM)    
 
Here we have to allocate space for char.

Manish said: (Fri, Feb 4, 2011 02:31:21 AM)    
 
I didnt understand about pointer,how it is work in c.

What is the difference between pointer of c and c++.?

Jadhi said: (Thu, Feb 10, 2011 06:26:31 AM)    
 
I want to know about malloc clearly.

Jeevanantham said: (Sat, Feb 12, 2011 01:29:43 AM)    
 
The malloc() function is a memory allocation type. It allocats memory in bytes and also return the pointer to allocated memory.

Minu Kutty said: (Sun, Feb 13, 2011 11:19:01 PM)    
 
I need complete details about pointers and c++ is better than c or not.

Vinoth said: (Fri, Mar 18, 2011 05:59:34 AM)    
 
Good example given by arunpandian

Rajesh said: (Mon, Mar 28, 2011 12:57:23 PM)    
 
Thanks kavyashri and mahesh for good explanation.

Abhijit Kamune said: (Mon, May 2, 2011 01:48:39 AM)    
 
Hey tell me where actually memory get allocate when we use malloc(), or calloc().

What is main diff between malloc() and calloc() ?

Prasath said: (Thu, May 19, 2011 02:31:16 AM)    
 
1) All memories allocated by memory management API's like malloc and calloc will be allocated from the Heap partition of the program.

2) Both malloc and calloc will allocate memories but, malloc just allocate required memory leaving the garbage value as it is but calloc allocate memory required and clear it with 0.

Krishna said: (Thu, Jun 9, 2011 05:34:23 AM)    
 
Can you combine two statements in pointers.

Krishna said: (Thu, Jun 9, 2011 05:36:13 AM)    
 
Can you explain pointe def and array def.

Ilyas said: (Wed, Jun 29, 2011 10:56:38 AM)    
 
Its very much simple many people have discussed in a lengthy way:

Understand 1st statement char*p, it means it stores the address of p let us its address is 1000. It means 1000---->p, clearly hear 1000 is pointing p, i.e char*p= p.

Replace p as char *p.

Fousiya said: (Tue, Jul 5, 2011 05:25:22 AM)    
 
Thanks Kavyasri

Divya said: (Tue, Jul 5, 2011 05:49:00 AM)    
 
Thanx kavyasree & mahesh........

Devi said: (Sat, Jul 16, 2011 05:48:41 AM)    
 
I want difference for pointer in c and c++?

Ravi said: (Fri, Aug 19, 2011 12:57:42 PM)    
 
The work of malloc function----->

> Malloc function allocate a fixed size block of memory from the heap and retuns a void type of pointer to it.
> Now we wont to store char type value in that memory so we have to convert the void type pointer to char type that's why (char *) is used to typecast the void pointer to char type.

The diff. between malloc and calloc------->
> syntaxt : data-type *p=(data-type *)malloc(size_t size);
> Malloc function allocates the a fixe size block of memory from the heap.
>syntaxt : data-type *p=(data-type *)calloc(size_t nsize,size_t size);
>Calloc function allocates the a size of (nsize *size) variable size block of memory from the heap.

Shailesh said: (Mon, Sep 12, 2011 11:10:38 PM)    
 
Please explain why we use a pointer.

With real time example.

Plz?

Prasanth said: (Sun, Sep 18, 2011 10:19:54 PM)    
 
Thanks kavya

Rahul Roy said: (Sun, Sep 25, 2011 09:51:59 AM)    
 
Because pointer indicate the address and point out that point. So the char*p indicate that point p.

Venkata Surendra said: (Thu, Sep 29, 2011 03:57:08 PM)    
 
The difference between c and c++ pointer is only one thing
c pointer is suspicious pointer nothing but a pointer variable which holds address un related type...
simple example
int x=10;
float *p;
p=&x;// it leads to logical error but c complier doesnt give any error same program if you save.cpp extension error will occur.

Paramjeet Singh said: (Mon, Oct 17, 2011 03:57:52 PM)    
 
First of all malloc is memory data type and p is character pointer data type. So as we know comparison is possible between two same entity so we will cast malloc as character pointer then equate at character pointer p.

Nandan said: (Sun, Nov 6, 2011 06:55:54 PM)    
 
Pointer returns the address of the located position in the memory...and malloc fun too returns the pointer of the space allocated..
i.e

char *p = (*char) malloc(---);

Meera said: (Fri, Jan 27, 2012 04:34:23 PM)    
 
malloc() function in c is used for allocating memory.

Following is the simple program using malloc function.

#include<stdio.h> /* For standard input output */
#include<malloc.h> /* You need this if on UNIX or LINUX */


int main()
{
char words[]={" this is a simple example for malloc\n"};
char *p; /* char pointer for use with malloc() */

p = (char *)malloc(sizeof(words)); /* Explained in the following text */
printf("words = %s\n",words);

return(0);
}

Write your comments here:
Name *:     Email:


© 2008-2011 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Advertise     Contact us: info@indiabix.com     Follow us on twitter!