main
in a more modern way!Starting with C++11, the auto declaration was implemented, which refers to the fact that a variable obtains the type automatically as long as it is immediately initialized.
And you can also use this in functions as well as in the main()
function in conjunction with the dash ->
bracket syntax and inform the type.
Your main function can be written like this: auto main() -> int {}
:
Now that you know, I think it’s worth using this syntax for your code to look more modern! :)
The arguments of the main function must be one of type int and the other a pointer of type char.
And whenever we use it we choose the argc names for the int type and the argv name for the array.
But that’s not a rule, you can choose the names you want. If you want to go outside the box, feel free to use your own names!
printf()
Whenever you want to print something on the screen, you need to use #
and the keyword include
right after that to include libraries such as: <stdio.h>
, <iostream>
to be able to use printf, correct? No, wrong.
You can use printf
without including anything, just create a function with the same name printf
inside an extern "C"
that receives a const char *
as a parameter and also the parameter three points ...
and your code will print your string smoothly!