The Gateway to Computer Science Excellence
0 votes
38 views

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

in Programming by (171 points) | 38 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
by Junior (837 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
50,650 questions
56,242 answers
194,294 comments
95,950 users