The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
36 views

what is the reason…..?for error..

asked in Programming by (171 points) | 36 views
0
sizeof(p) ? What is p here?
0

am also confusing about p.

I got this from geeksfrom geeks

0
Malloc allocates memory at runtime( dynamically).

whereas static allocates memory at compile time itself.

You are giving contradicting memory allocation methods. hence the error.
0

But it is working in c++ and in the link proveded above is saying that the error is because of

initializing global and static variables must be constant not expression.am thinking that the error is about the the initialization.can you tell me which one is correct......

 what is p in sizeof(p) 

1 Answer

0 votes
during initialization itself you are using p and also assignment operator has right assosiativity so it finds what is this p

If you do

static int*p;

p=(int *) malloc(sizeof(p))

then its working
answered by Junior (789 points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,811 questions
54,530 answers
188,404 comments
75,484 users