+ 1

Can anyone explain this code?It gives errors and i am not able to understand it clearly??

https://code.sololearn.com/c7Joo3x2qrFl/?ref=app

12th Dec 2017, 3:07 PM
looper
looper - avatar
7 Answers
+ 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)
12th Dec 2017, 3:17 PM
Anisim
+ 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.
12th Dec 2017, 3:37 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
+ 1
@Anisim actually it works in c language.. N my aim is to print the size of memory allocated to p,q,r
12th Dec 2017, 3:34 PM
looper
looper - avatar
+ 1
But why we need to use comma there??
12th Dec 2017, 3:40 PM
looper
looper - avatar
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.
12th Dec 2017, 3:38 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
- 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.
12th Dec 2017, 3:33 PM
John Wells
John Wells - avatar
- 1
because you are defining 2 variables far and q
12th Dec 2017, 4:08 PM
John Wells
John Wells - avatar