C++ Programming Basics

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

What is the only function that all C++ programs must contain?

  • start()
  • system()
  • program()
  • main() (correct)

What is the purpose of comments in a C++ program?

  • Functions
  • Arrays
  • Comments (correct)
  • Looping

What is a location in the computer's memory that may contain different values at various times throughout the execution of a program?

  • statement
  • memory
  • variable (correct)
  • constant

Which of the following is a valid variable name in C++?

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

Which of the following data types is assigned only an integer value 1 or 0?

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

What is the correct way to declare a variable as a string?

<p>char str = &quot;Hello&quot;; (A)</p> Signup and view all the answers

Which of the following is a valid variable declaration?

<p>int a; (D)</p> Signup and view all the answers

What is the object used to input values from the keyboard?

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

What is the correct way to declare a constant variable?

<p>const float PI = 3.14; (C)</p> Signup and view all the answers

What is the output of the statement cout << x + y << endl;

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

Flashcards are hidden until you start studying

Study Notes

C++ Basics

  • The only function that C++ programs must contain is main().

Code Blocks

  • Code blocks in C++ are signaled by { and } punctuation.

Statements

  • Every statement in C++ should end with a ; (semicolon).
  • . (dot) is not used to end statements.

Comments

  • Comments are used to document a program and improve its readability.
  • Comments can be written using / */*, but not \.
  • Comments are neglected by the compiler.
  • Comments can be written anywhere in the program, not just at the top.

Variables

  • A variable is a location in the computer's memory that may contain different values at various times throughout the execution of a program.
  • Variable names can start with _ (underscore), but not with a number or space.
  • A valid variable name is delta_univ, but not delte univ or delta-univ.

Data Types

  • bool is a data type that can only be assigned an integer value of 1 or 0.
  • float and double are valid data types, but real is not.
  • char is a data type used to define a single character, and can be declared as char ch = 'Z';.

Variable Declaration

  • A valid variable declaration is int a;, but not int a,, int a, or int a:.

Constants

  • A correct declaration of a constant is const float PI = 3.14;, but not float PI 3.14; or # define PI = 3.14;.

Input/Output Objects

  • The object used to print information on the screen is cout.
  • The object used to input a value from the keyboard is cin.

Studying That Suits You

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

Quiz Team

Related Documents

More Like This

C++ Programming Tutorial
22 questions
Introduction to Computer Programming
19 questions

Introduction to Computer Programming

LargeCapacitySnowflakeObsidian2219 avatar
LargeCapacitySnowflakeObsidian2219
Introduction to Computer Programming and C++
9 questions

Introduction to Computer Programming and C++

LargeCapacitySnowflakeObsidian2219 avatar
LargeCapacitySnowflakeObsidian2219
Use Quizgecko on...
Browser
Browser