The Gateway to Computer Science Excellence
0 votes

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

in Programming by (171 points) | 38 views
sizeof(p) ? What is p here?

am also confusing about p.

I got this from geeksfrom geeks

Malloc allocates memory at runtime( dynamically).

whereas static allocates memory at compile time itself.

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

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 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
95,950 users