Is the "new" keyword used in C?
Example of use in C++:
struct Person* ron = new Person;
Is the "new" keyword used in C?
Example of use in C++:
struct Person* ron = new Person;
For further actions, you may consider blocking this person and/or reporting abuse
Aarti Jangid -
DeveloperTom404 -
Oleksandr Volkovitskiy -
Sharon428931 -
Top comments (2)
I think the answer is no -
newin C++ is used for classes and structs to initialize a new instance, C has structs (only), and you declare them like any other variable type.You can see the
struct Namegets repeated a lot, it's normal to use a typedef in that situation to make that shorter, usually in the header:There is also support for initializing the members during the definition (if you search for "designated initializer" that's probably the standard name for this):
newanddeletework around a lot of the chores of usingmallocandfree, but are C++ only.Thanks Daniel, this is a really big help for me. Thanks for including the method for doing it properly too!
Some comments may only be visible to logged-in visitors. Sign in to view all comments.