Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: Data types variables and all related to different operators
Description: It contains info on data types,operators etc in C++ programming.It can be studied by 1st year beginner or anyone with decent computer knowledge.

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


unsigned long int
long long int
unsigned long long
int
signed char
unsigned char
float
double
long double

4
8
8
1
1
4
8
16

0 to 4,294,967,295
-(2^63) to (2^63)-1
0 to
18,446,744,073,709,551,615
-128 to 127
0 to 255

%lu
%lld
%llu
%c
%c
%f
%lf
%Lf

2
...
2
...
All variables must be declared before they can be used
...
Here are some declarations:
int i, j, l;
short int si;
unsigned int ui;
double balance, profit, loss;

2
...
2 Scope
Variables can be declared in three places: inside functions, in the definition of function parameters,
and outside of all functions
...

A) Local Variables
Variables that are declared inside a function are called local variables
...
In other words, local
variables are not known outside their own code block
...
Furthermore, a variable declared
within one code block has no bearing on or relationship to another variable with the same name
declared within a different code block
...
The x in func1( ) has
no bearing on or relationship to the x in func2( )
...
Consider the
following:
#include ...
These variables are called the formal parameters of the function
...

/* Return 1 if c is part of string s; 0 otherwise */
int is_in(char *s, char c)
{
while(*s)
if(*s==c)
return 1;
else s++;
return 0;
}

C) Global Variables
Unlike local variables, global variables are known throughout the program and may be used by any
piece of code
...
You create global
variables by declaring them outside of any function
...

In the following program, the variable count has been declared outside of all functions
...
However, it is usually best to declare global variables at the top of
the program
...
h>
int count; /* count is global */
void func1(void);
void func2(void);
int main(void)
{
count = 100;
func1();
return 0;
}
void func1(void)
{

int temp;
temp = count;
func2();
printf("count is %
d", count); /* will print 100 */
}
void func2(void)
{
int count;
for(count=l; count<10; count++)
putchar('
...


2
...
extern
2
...
register
4
...
The general form of a variable
declaration that uses one is shown here:
storage_specifier type var_name;
2
...
1 extern
The principal use of extern is to specify that an object is declared with external linkage elsewhere in
the program
...
A declaration declares the name and type of an object
...
The same object may have many declarations,
but there can be only one definition
...

Here is an example that uses extern
...

#include ...
Because the extern declaration tells the compiler that first and last are
declared elsewhere (in this case, later in the same file), the program can be compiled without error
even though first and last are used prior to their definition
...
However, if you give that variable an initialization, the extern
declaration becomes a definition
...
3
...
Unlike global
variables, they are not known outside their function or file, but they maintain their values between
calls
...
The static modifier has different effects upon local variables and global
variables
...
The key difference between a static local variable and
a global variable is that the static local variable remains known only to the block in which it is
declared
...
static local variables are very important to the creation of stand-alone functions
because several types of routines must preserve a value between calls
...
This means that each call to series( ) can produce a
new member of the series based on the preceding number without declaring that variable globally
...
This value is assigned only once, at
program start-up— not each time the block of code is entered, as with normal local variables
...
This means that even though the variable is global,
outines in other files have no knowledge of it and cannot alter its contents directly, keeping it free
from side effects
...
3
...

However, in Standard C, register's definition has been broadened so that it can be applied to any type
of variable
...
This meant that
operations on a register variable could occur much faster than on a normal variable because the
register variable was actually held in the CPU and did not require a memory access to determine or
modify its value
...
You don't have to worry
about declaring too many register variables because the compiler automatically transforms register
variables into nonregister variables when the limit is reached
...
3
...
Auto stands for automatic
storage class
...


2
...
4
...

The value of the right side (expression side) of the assignment is converted to the type of the left side
(target variable), as illustrated here:
int x;
char ch;
float f;
void func(void)
{
ch = x; /* line 1 */
x = f; /* line 2 */
f = ch; /* line 3 */
f = x; /* line 4 */
}

In line 1, the left high-order bits of the integer variable x are lopped off, leaving ch with the lower 8
bits
...
Otherwise, the value of ch
would reflect only the lower-order bits of x
...
In line
3, f will convert the 8-bit integer value stored in ch to the same value in the floating-point format
...

Casts
You can force an expression to be of a specific type by using a cast
...
For example, to cause the expression x/2 to evaluate
to type float, write
(float) x/2

Spacing and Parentheses

x = y/3-34*temp+127;
x = (y/3) - (34*temp) + 127;
both are equal but second one is more readable

2
...
2 Arithmetic Operators
Operator
+
*
/
%
-++

Action
Subtraction, also unary minus
Addition
Multiplication
Division
Modulus
Decrement by one
Increment by one

Both the increment and decrement operators may either precede (prefix) or follow (postfix) the
operand
...
If the operator
follows its operand, the value of the operand is obtained before incrementing or decrementing it
...
However, if you write the code as
x = 10;
y = x++;

y is set to 10
...

2
...
3 Relational Operators
Operator
Action
>
Greater than
>=
Greater than or equal
<
Less than
<=
Less than or equal

==

Equal

!=

Not equal

2
...
4Logical Operators
Operator
Action
&&
AND
||
OR
!
NOT
Bitwise Operators
Operator
&
|
^
~
>>
<<

Action
AND
OR
Exclusive OR (XOR)
One's complement (NOT)
Shift right
Shift left

2
...
5 The Compile-Time Operator sizeof
sizeof is a unary compile-time operator that returns the length, in bytes, of the variable or
parenthesized type specifier that it precedes
...

double f;
printf("%d ", sizeof f);
printf(''%d", sizeof(int));

{Ref: https://www
...
org/operator-precedence-and-associativity-in-c/}

2
...

All operators with the same precedence have same associativity
Precedence and associativity of postfix ++ and prefix ++ are different
Comma has the least precedence among all operators and should be used carefully

Additional:
Language Standards Supported by GCC(GNU Compiler Collection)
...
Although support for the most recent
version is not yet complete
...


C99 - This was a past version of the C programming language standard
...
New built-in data types: long long,
_Bool, _Complex, and _Imaginary

C11 - C11 is the current standard for the C programming language
...
Type-generic
expressions using the new _Generic keyword, a cross-platform multi-threading API
(threads
...
h)
...
The first region is
the memory that actually holds the program's executable code
...
The remaining two regions are the stack and the heap
...
It holds the return addresses of function calls,
arguments to functions, and local variables
...
The heap is
a region of free memory that your program can use via C's dynamic memory allocation functions
...


Type Qualifiers
C defines type qualifiers that control how variables may be accessed or modified
...
C99 adds a third, called restrict, which is described in Part Two
...

const int a=10;

volatile
The modifier volatile tells the compiler that a variable's value may be changed in ways not explicitly
specified by the program
Title: Data types variables and all related to different operators
Description: It contains info on data types,operators etc in C++ programming.It can be studied by 1st year beginner or anyone with decent computer knowledge.