That is why I ask my students to attend classes regularly, even though the lecture notes are available on Google Classroom and can be downloaded and read at any time.
The same applies in your case. To get clear answers to your questions, you need to attend interactive online or practical lectures (with audio/video). These are the same types of questions I also raised when I started learning C about 25 years ago.
In any case, I will try to answer some of your questions, although I am not a serious/practicing C++ programmer.
@skybear
1. int main()
Q11: Whys is int before main()?
A11: In the English language, there are parts of speech, and each part has a name. Typically, the noun/subject appears before the verb. This is not a rule; rather, a style in which native speakers have been speaking and writing for hundreds of years. Over time, this usage has been documented and formalized as a rule in English grammar books.
Similarly, in the C++ language, there are tokens, and each token has a name and defined role. In the statement int main(), the tokens are int, main, (, and ). Since C++ is an artificial language, it has explicit syntax rules that dictate where each token must be placed. According to these rules, int (data type) appears before main() (function name), a convention that we learn and remember through practice.
Q12: Is there any other example where int goes before another token?
A12: int myData;. Here, myData is a variable/identifier. The int token is called data type, and it says that the myData variable can hold 16-bit data.
Q13: Can you explain with an example the meaning of int main() style?
A13: These are the codes to add two numbers:
void setup()
{
int y1 = 0x1234; //0x indicates that the next digits have 16-base (hex base)
int y2 = 0x5678;
int sum = y1 + y2; //sum = 0x68AC
}
The above code can be written in the following style that resembles int main() structure. This formatting style has a specific advantage: the setup() function remains clean and uncluttered, instead of being populated with many lines of code. Here, I have pesented a simple example.
void setup()
{
int y1 = 0x1234; //0x indicates that the next digits have 16-base (hex base)
int y2 = 0x5678;
int sum = add(y1, y2); //we call add() which returns int (16-bit) type result
}
int add(in p, int q)//p gets value of y1; q gets value of y2; add() returns 16-bit data
{
int result = p + q; //result holds 0x5678
return(result); //the value of ressult is assigned to variable sum
}
Given below an integrated version of the above fragmented codes, which you can upload and execute in UNOR4 board.
void setup()
{
Serial.begin(9600);
int y1 = 0x1234; //0x indicates that the next digits have 16-base (hex base)
int y2 = 0x5678;
int sum = add(y1, y2); //we call add() which returns int (16-bit) type result
Serial.println(sum, HEX); //shows: 68AC
}
void loop()
{
}
int add(int p, int q)//p gets value of y1; q gets value of y2; add() returns 16-bit data
{
int result = p + q; //result holds 0x5678
return (result); //the value of result is assigned to variable sum
}
@skybear
2. #include
Q21: What is the name of # symbol in C++ language?
A21: In C++, it is called preprocessor (marker).
Q22: What is the name of include token?
A22: It called preprocessor directive.
Q23: Then what is meaning of #include<SoftwareSerial.h>?
A23: The directive instructs the compiler to copy and paste all the contents of the file named SoftwareSerial.h (located in the working directory of your PC) at the top of the sketch or program. During compilation, the compiler performs optimization and retains only the code and structures that are actually needed by your sketch. A header file (*.h) may contain many functions, but typically only a few of them are used in your sketch.
Q24: Why is #include <SoftwareSerial.h> instead of
#include "SoftwareSerial.h"?
A24: You have asked the Compiler to include the file named SoftwareSerial.h in your sketch. This is not enough; you must give necessary instruction to the Compiler which folder to look first for the file. The pair of double quotes (" and ") tells the Compiler to look for the file in the Project Folder"; whereas, pair of angle brackets (< and >) instructs to look into System Folder.
3. Meaning of std::cout << "Hello World!"
................
.... in progress