+ 1
Can anyone explain this code?It gives errors and i am not able to understand it clearly??
7 odpowiedzi
+ 3
errors at 6 and 7 lines
to make a pointer you should use syntax:
(type_of_data) *(pointer_name);
ex.: int *p;
if you want give an address of variable:
char *p = &var;
in your code:
char *p;
char *q;
char *r;
but sizeof(p) gives you only size of address)
+ 2
#include <iostream>
using namespace std;
int main() {
char *p;
char far *q; //error
char huge *r; //error
cout<<sizeof(p);
cout<<sizeof(q);
cout<<sizeof(r);
return 0;
}
You can clear error as below,
char huge, *r;
char far, *q;
here huge and far are variables of char type and r and q are pointer of char type.
+ 1
@Anisim actually it works in c language.. N my aim is to print the size of memory allocated to p,q,r
+ 1
But why we need to use comma there??
0
And yes sizeof any pointer is 4 bytes for 32 bit system thats why even for char pointer you are getting size as 4.
- 1
You are defining far as a char and need a comma before the * to define q.
char far *q;
Based on what you have going on, I'm guessing you wish to get the size of some types. This could be used to do this.
typedef char far[100];
far q;
cout<<sizeof(q);
outputs 100.
- 1
because you are defining 2 variables far and q