what is (*this) in c language?
Mia Lopez
what is this pointer? it doesn't work in linux..but in visual studio it work what happened??
#include <stdio.h> #include <string.h> #include<stdlib.h> typedef struct { char name[20]; int id; } person ; // this function is my main problem void print(person *this){ printf("%s %d\n",this->.name,this->id); } int main(){ person p, q; strcpy(p.name, "a"); p.id=60151234; strcpy(q.name, "b"); q.id=60155678; print(&p); print(&q); system("pause"); return 0; } 5 2 Answers
In C, this is a normal parameter name, no different from any other name.
You're probably using a C++ compiler, where this is a keyword and will give an error when used as a parameter.
In C++, this is a reserved word used in class methods as a pointer to the object in question. It is not a reserved word in C, so in this case it's simply the name of the parameter.
This code will compile fine with gcc (provided you change this->.name to this->name), but it will not compile with g++ for this reason.