Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on Why use an asterisk after a type?
Parent
Why use an asterisk after a type?
#include<stdio.h>
struct Node{
int data;
struct Node* next;
};
Here I used an asterisk after Node. What is it used for? What if I don't put any asterisk after Node (both Node's are structures)?
Is *ptr and ptr* same?
Post
The * for variables and not mathematical operators are the pointers.
Assigning a pointer goes this way:
char *text; // string
Here, we assign a pointer named text and its type is a char, but alternatively, this is a string.
As for your question, int *ptr is basically the same as int* ptr, only being a pointer of an int, and nothing else. Your given struct Node* next is the same as struct Node *next, and I don't think ptr* even exists, unless it's made as some union or struct. struct *Node wouldn't work likely.

1 comment thread