Naming Conventions: Camelcase vs Snakecase

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which of the following best describes the concept of initialization in programming?

  • Manipulating a variable's value during program execution
  • Declaring a variable without assigning it any value
  • Giving a variable an initial value at the time of declaration (correct)
  • Assigning a variable a value after it has already been declared

What is the purpose of naming conventions in programming?

  • To prevent variables from being initialized
  • To make the code more confusing for other programmers
  • To limit the number of variables that can be used in a program
  • To ensure that variables have meaningful and consistent names (correct)

Which of the following is an example of a legal identifier in programming?

  • _variableName (correct)
  • 3totalAmount
  • variable Name
  • $moneyAmount

What is the importance of using meaningful variable names in programming?

<p>To make the code more readable and maintainable (C)</p> 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?

<p>camelCase (C)</p> Signup and view all the answers

Which naming convention involves starting with a lowercase letter and capitalizing the first letter of each subsequent word?

<p>camelCase (A)</p> Signup and view all the answers

In the context of naming conventions, which of these is a correct example of snakecase?

<p>my_value (C)</p> Signup and view all the answers

Why is it important to use meaningful names for variables in programming?

<p>To indicate the meaning or use of the stored value (D)</p> Signup and view all the answers

Which of the following is NOT a legal identifier in C++?

<p>$amount (D)</p> Signup and view all the answers

Choose the statement that correctly describes variable declaration in C++.

<p>Variables must be declared before they are used (A)</p> Signup and view all the answers

Which of the following is a common misconception about naming conventions?

<p>'kebab-case' involves capitalizing every word in an identifier (B)</p> Signup and view all the answers

Which character is NOT allowed in C++ identifiers?

<p>A hyphen (-) (B)</p> Signup and view all the answers

What is the correct naming convention for the following identifier: 'totalAmountOfSales'?

<p>total_amount_of_sales (D)</p> Signup and view all the answers

Which of the following C++ identifiers is legal?

<p>_averageScore (A)</p> 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?

<p>camelCase (B)</p> Signup and view all the answers

Which of the following identifier names adheres to good practice and is meaningful?

<p>totalSalesValue (D)</p> Signup and view all the answers

Given the identifier 'RATE.CPP', why is it considered illegal in C++?

<p>'RATE' cannot be followed by a period in identifiers. (D)</p> Signup and view all the answers

Flashcards are hidden until you start studying

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 not 1600CISC, $cash, my-Value, or RATE.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;, or char 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 &lt;&lt; faculty;.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

More Like This

Use Quizgecko on...
Browser
Browser