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
windmillcode0 -
windmillcode0 -
11 -
Dorian Sabitov -
Top comments (2)
I think the answer is no -
new
in 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 Name
gets 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):
new
anddelete
work around a lot of the chores of usingmalloc
andfree
, 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.