C++ Programming Basics

AwedNashville avatar
AwedNashville
·
·
Download

Start Quiz

Study Flashcards

10 Questions

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

main()

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

Comments

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

variable

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

delta_univ

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

bool

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

char str = "Hello";

Which of the following is a valid variable declaration?

int a;

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

cin

What is the correct way to declare a constant variable?

const float PI = 3.14;

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

6

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.

Test your knowledge of the fundamental concepts of C++ programming language, including functions and code blocks.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Week 2 Computer Programming C++
10 questions
Week 2 Computer Programming C++
10 questions
C++ Programming Tutorial
22 questions
C++ Programming Concepts
55 questions
Use Quizgecko on...
Browser
Browser