Structs
Structs in Computer Programming
struct Point {
int x, y;
// Constructor in C++
Point(int x, int y) : x(x), y(y) {}
};
int main() {
// Creating and using an instance of the struct
Point p(1, 2);
printf("Point coordinates: (%d, %d)\n", p.x, p.y);
return 0;
}struct Point {
public int X, Y;
public Point(int x, int y) {
X = x;
Y = y;
}
}
class TestStructs {
static void Main(string[] args) {
// Creating and using an instance of the struct
Point p = new Point(1, 2);
Console.WriteLine($"Point coordinates: ({p.X}, {p.Y})");
}
}Last updated
Was this helpful?