Podcast
Questions and Answers
Which of the following best describes the concept of initialization in programming?
Which of the following best describes the concept of initialization in programming?
What is the purpose of naming conventions in programming?
What is the purpose of naming conventions in programming?
Which of the following is an example of a legal identifier in programming?
Which of the following is an example of a legal identifier in programming?
What is the importance of using meaningful variable names in programming?
What is the importance of using meaningful variable names in programming?
Signup and view all the answers
In programming, which naming convention usually capitalizes the first letter of each word and joins them together without spaces?
In programming, which naming convention usually capitalizes the first letter of each word and joins them together without spaces?
Signup and view all the answers
Which naming convention involves starting with a lowercase letter and capitalizing the first letter of each subsequent word?
Which naming convention involves starting with a lowercase letter and capitalizing the first letter of each subsequent word?
Signup and view all the answers
In the context of naming conventions, which of these is a correct example of snakecase?
In the context of naming conventions, which of these is a correct example of snakecase?
Signup and view all the answers
Why is it important to use meaningful names for variables in programming?
Why is it important to use meaningful names for variables in programming?
Signup and view all the answers
Which of the following is NOT a legal identifier in C++?
Which of the following is NOT a legal identifier in C++?
Signup and view all the answers
Choose the statement that correctly describes variable declaration in C++.
Choose the statement that correctly describes variable declaration in C++.
Signup and view all the answers
Which of the following is a common misconception about naming conventions?
Which of the following is a common misconception about naming conventions?
Signup and view all the answers
Which character is NOT allowed in C++ identifiers?
Which character is NOT allowed in C++ identifiers?
Signup and view all the answers
What is the correct naming convention for the following identifier: 'totalAmountOfSales'?
What is the correct naming convention for the following identifier: 'totalAmountOfSales'?
Signup and view all the answers
Which of the following C++ identifiers is legal?
Which of the following C++ identifiers is legal?
Signup and view all the answers
What is the naming convention used in C++ where the first letter of each word except the first word is capitalized?
What is the naming convention used in C++ where the first letter of each word except the first word is capitalized?
Signup and view all the answers
Which of the following identifier names adheres to good practice and is meaningful?
Which of the following identifier names adheres to good practice and is meaningful?
Signup and view all the answers
Given the identifier 'RATE.CPP', why is it considered illegal in C++?
Given the identifier 'RATE.CPP', why is it considered illegal in C++?
Signup and view all the answers
Study Notes
Identifiers and Naming Conventions
- Identifiers must start with a letter (A-Z or a-z) or an underscore (_).
- Identifiers can be of any length, but C++ is case-sensitive.
- Legal identifier names include
CISC1600
,RATE
, and_RATE
, but not1600CISC
,$cash
,my-Value
, orRATE.CPP
. - Two common naming conventions are Camelcase and Snakecase (or "C-Style").
- Camelcase: start with a lowercase letter, and capitalize the first letter of each subsequent word in a compound word or phrase.
- Snakecase: use underscores between compound words and longer phrases, with no additional capitals.
Variable Declarations
- All variables in a C++ program must be declared.
- A variable declaration gives the variable a name, e.g.
int myVar;
,double RATE;
, orchar firstInitial;
. - Variables can be initialized with a value during declaration, e.g.
int numOfStudents = 10;
.
Variables and Assignments
- Variables are used to store and name data.
- A variable's value can be changed later in the program.
- If a variable is given no value when it is created, it will have a garbage value until it is assigned a value.
- Each variable is assigned an address/memory location when the program is compiled.
- The value assigned to a variable is stored in that memory location while the program runs.
Assignment Statements
- A variable has no meaningful value until it is assigned one.
- Example of assignment:
desiredValue = minValue + 25;
. - Uninitialized variables store garbage data and can have different values each time the program is run.
- Variables can be initialized with a value during declaration, e.g.
int minValue = 10;
. - Multiple variables can be initialized with values during declaration, e.g.
double rate = 0.07, time, balance = 0.0;
.
Input and Output
- Streams can be used to feed input from a source into a program or send output generated by the program.
-
cout
is used to output strings of text or the value of variables. - Example of output:
int faculty = 26; cout << faculty;
.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Learn about the common naming conventions used for identifiers in programming, such as Camelcase and Snakecase. Understand how these conventions make identifiers consistent and easier to read at a glance.