0% found this document useful (0 votes)
142 views4 pages

What Is A Header File?: Variables

The document discusses several key concepts in C++ including header files, variables, data types, and math functions. Header files contain function and variable definitions that can be included in a C++ program using #include. Variables must be declared before use and have specific naming rules. Primitive data types in C++ store integers, characters, booleans, floats, and void values. Common math functions like max, min, square root, round, and log are in the cmath header file.

Uploaded by

WAVEFORMS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
142 views4 pages

What Is A Header File?: Variables

The document discusses several key concepts in C++ including header files, variables, data types, and math functions. Header files contain function and variable definitions that can be included in a C++ program using #include. Variables must be declared before use and have specific naming rules. Primitive data types in C++ store integers, characters, booleans, floats, and void values. Common math functions like max, min, square root, round, and log are in the cmath header file.

Uploaded by

WAVEFORMS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

What is a header file?

Header files contain definitions of Functions and Variables, which is imported or used into any C++
program by using the pre-processor #include statement. Header file have an extension ".h" which
contains C++ function declaration. Some of the header files:-

 #include<stdio. h> (Standard input-output header)


 #include<string. h> (String header)
 #include<conio. h> (Console input-output header)
 #include<stdlib. h> (Standard library header)
 #include<math. h> (Math header )

What is the meaning of line # include


<iostream. h>?
#include<iostream.h> is used in C++ in order to include the header file “iostream” in the
program. Iostream is used to invoke the commonly used functions like cout,cin in a C++
program. Iostream stands for input output stream.

VARIABLES:-
A variable is a name given to a memory location. It is the basic unit of storage in a program. The
value stored in a variable can be changed during program execution.

In C++, all the variables must be declared before use.

Difference between variable declaration and definition


The variable declaration refers to the part where a variable is first declared or introduced before
its first use. A variable definition is a part where the variable is assigned a memory location and
a value. Most of the times, variable declaration and definition are done together.
Following are the rules for naming variables −

  Variable names in C++ can range from 1 to 255 characters.


  All variable names must begin with a letter of the alphabet or an underscore(_).
  After the first initial letter, variable names can also contain letters and numbers.  
  Variable names are case sensitive.
  No spaces or special characters are allowed.
  You cannot use a C++ keyword (a reserved word) as a variable name.

Here are some examples of acceptable variable names :-

For example:-
C++ Data Types:-
All variables use data-type during declaration to restrict the type of data to be
stored. Therefore, we can say that data types are used to tell the variables the type
of data it can store. Every data type requires a different amount of memory.

Primitive data types available in C++:-


 Integer: Keyword used for integer data types is int. Integers typically requires 4 bytes
of memory space and ranges from -2147483648 to 2147483647.
 Character: Character data type is used for storing characters. Keyword used for
character data type is char. Characters typically requires 1 byte of memory space and
ranges from -128 to 127 or 0 to 255.
 Boolean: Boolean data type is used for storing boolean or logical values. A boolean
variable can store either true or false. Keyword used for boolean data type is bool.
 Floating Point: Floating Point data type is used for storing single precision floating
point values or decimal values. Keyword used for floating point data type is float. Float
variables typically requires 4 byte of memory space.
 void: Void means without any value. void datatype represents a valueless entity. Void
data type is used for those function which does not returns a value.
C++ Math:-
Max and min

The max(x,y) function can be used to find the highest value of x and y:

Example
cout << max(5, 10);

And the min(x,y) function can be used to find the lowest value of x and y:

Example
cout << min(5, 10);

Some of the other functions, such as sqrt (square root), round (rounds a number) and log
(natural logarithm), can be found in the <cmath> header file:

Example

#include <cmath>
cout << sqrt(64);
cout << round(2.6);
cout << log(2);

cout <<pow(2,3)

OUTPUT:-

0.693147

Test Yourself With Exercises:-


https://www.w3schools.com/cpp/exercise.asp?filename=exercise_math1

You might also like