C++ Statements and Data Types

A C++ function is nothing but a sequence of statements.A statement is like an instruction.It is terminated by a semi-colon( ; ). There are different types of C++ statements that are used in C++. They are:

  • Declarations – Declarations are used to declare variables or constants that will be used in the C++ program.

  • Assignments – Assignments are used to assign particular values to the variables in the C++ program.

  • Preprocessor Directives – Preprocessor Directives are invoked by the compiler to process some programs before compilation.

  • Function Declaration – A function declaration tells us about the function name,return type and parameters.

  • Executable Statements – Executable statements are used to perform operations and computations.

  • Comments – Comments are used for making the code more readable and understandable. Comments are not compiled by the compiler.

C++ Data types

Data types tell the variable the type of data it can store. C++ contains intrinsic or built-in data types to store different types of data in your C++ program. Whenever a variable is defined in C++, the compiler allocates some memory for that variable based on the data-type with which it is declared.

  • For numeric data or numbers,the main data types are int,float and double.The memory of int,float and double are 4,4 and 8 bytes respectively.

  • For  characters or letters or symbols, the data type is char which is of 1 byte.

  • Other data type used is bool for Boolean data type.It is also 1 byte and can have only 2 values True or False.

  • The unsigned keyword is a data type specifier, that makes a variable only represent positive numbers and zero. It can be applied only to the char,short,int and long types. For example, if an int typically holds values from -32768 to 32767, an unsigned int will hold values from 0 to 65535. You can use this specifier when you know that your variable will never need to be negative.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: