Saturday, June 30, 2018

C programming decision making



Decision making in C programming have structures. These decision making structures require programmers to specify either one or more than one statements. In last chapter, you studied C operators. However, this chapter is about C decision making statements. You will also learn C decision making statements.

Decision making C lesson

Furthermore, programmers specify conditions. Because program will test these conditions. In addition, program will test statement, which it will execute. It happens only when condition is true. In addition, it may continue process when condition is false.

Points to remember

  • C program language will assume that non zero as well as non null values are true
  • In case it is zero or null then it will take as false value
You can continue reading to know decision making statements type. You will also know use of decision making C programming language use.

Lists of decision making statements with description in C

Name of the statementDescription
if…else statementOptional else statement may follow this statement. Because this will execute only when Boolean expression is false
if statementHowever, if statement has Boolean expression. After this there can be either one or more than one statements
switch statementBut switch statement will allow variable to test. This test is to check equality against list of values
nested if statementsC programming language allows you to use either one if or else if statement. In addition, you may use it in another if or else if statement or statements
nested switch statementsFinally, you may use one switch statement in another switch statement or statements


? : operator in C programming language decision making

You must remember that conditional operator ? : replaces if…else statements.

General form of conditional operator ? : is

Exp1 ? Exp2 : Exp3;
In the above general form, expressions are Exp1 and Exp2. Even Exp3 is an expression. Moreover, you can check how we used expressions. Furthermore, colon is also applicable.

How to define value of ? expression

For this, you should follow the rules. When you evaluate Exp1. Moreover, if it turns true. In such cases, Exp2 evaluates. In addition, this will be value of entire ? expression.
However, in cases where Exp1 is false. Then you must evaluate Exp3. As a result value of Exp3 is value of complete expression.
Thus, you learnt C programming decision making and branching. In addition, you also got to know C programming decision making examples. So, practice C decision making programs in C language examples. Because this will help you in C loops chapter.




























C programming operators


What is operator in C programming language?

Operator in C is a symbol. It will tell compiler to perform either mathematical or logical functions. Moreover, in C programming language there are many C operator programs. You will find here complete list of C operators in C with examples.

List of C arithmetic operators

Name of the operatorDescription
+It will add two operands
/Divides numerator by the de-numerator
*Operator will multiply both operands
It will subtract second operand from first operand
++This operator is increment operator. It will increase integer value by one
%This is a modulus operator. And remainder of after integer division
It is decrement operator. It decreases integer value by one
Program examples

Logical operators list in C programming language

Operator’s nameDescription
||This is Logical OR Operator. When any two operands is non-zero. Then condition becomes true
!It is Logical NOT Operator. You can use it to reverse logical state of operand. In addition, when condition is true, then Logical NOT operator makes it false
&&Finally, this is Logical AND operator. In case, both operands are non-zero. Then condition will become true
Example programs

Relational operators in C language

Operator’s nameDescription
!=It checks values of two operands are equal or not. When values are not equal. Then condition becomes true
==Checks values of two operands are equal or not. When yes, then condition will become true
<Checks value of left operand is less than value of right operand. And if yes. Then condition will be true
>Checks value of left operand is greater than value of right operand. In case yes, then condition will be true
>=This operator will check value of left operand is greater than or equal to value of right operand. Moreover, if yes, then condition changes to true
<=It will check value of left operand is less than or equal to value of right operand. Furthermore, if yes, then condition will be true
Example programs


List of C language bitwise operators

Name of the operatorDescription
|This is Binary OR Operator. It copies bit if it is there in either operand
&Binary AND Operator will copy bit to result if there in both operands
<<It is Binary Left Shift Operator. Here, left operands value moves left by
number of bits. Moreover, right operand specifies bits
>>Binary Right Shift Operator. Here, left operands value moves right by number of bits. Again right operand will specify bits
^Binary XOR Operator will copy bit when it is set in one operand only
~Finally, this is Binary Ones Complement Operator. It is unary. Additionally, it has effect of flipping bits
Example programs

List of Misc Operators – sizeof & ternary operators in C

Operator’s nameDescription
? :It is conditional expression
sizeof()It will return size of variable
*It will point to variable
&& returns address of variable
Program examples

Assignment operators of C language

OperatorDescription of the operator
=Simple assignment operator will assign values from right side operand to left side operand
-=This is Subtract AND assignment operator. It will subtract right operand from left operand. Moreover, it assigns result to left operand.
+=Add AND assignment operator. It will add right operand to left operand. Moreover, assigning result to left operand is its responsibility
%=This is Modulus AND assignment operator. In addition, it will take modulus using two operands. In addition, it assigns result to left operand
*=Multiply AND assignment operator multiplies right operand with left operand. It will also assign result to left operand
/=Divide AND assignment operator divides left operand with right operand. In addition, it will assign result to left operand
&=It is Bitwise AND assignment operator
<<=This operator is Left shift AND assignment
>>=It is Right shift AND assignment operator
|=Bitwise inclusive OR and assignment operator
^=Finally, this operator is Bitwise exclusive OR and assignment
Example programs

C operators precedence and associativity

An operator precedence will decide grouping of terms in expressions. It will also decide how to evaluate expressions. However, you must remember that few C operators will have more precedence than the others.
You can check below list. Because here you will know C operators precedence and associativity. In addition, table has highest precedence operator first. In addition, the list will go from higher to lower precedence. You may even look at C operators associativity.

List of C operators precedence and associativity in C programming language

Name of the categoryAssociativityOperator
PostfixLeft to right() [] -> . ++ – –
UnaryRight to left+ – ! ~ ++ – – (type)* & sizeof
MultiplicativeLeft to right* / %
AdditiveLeft to right+ –
ShiftLeft to right<< >>
RelationalLeft to right< <= > >=
EqualityLeft to right== !=
Bitwise ANDLeft to right&
Bitwise XORLeft to right^
Bitwise ORLeft to right|
Logical ANDLeft to right&&
Logical ORLeft to right||
ConditionalRight to left?:
AssignmentRight to left= += -= *= /= %=>>= <<= &= ^= |=
CommaLeft to right,
Program examples





So now you know C operators programs examples. Practise C operators in C and C operators precedence. This will help you with C functions chapter.










C programming storage classes



C storage class is another topic in C language. Here you will learn C storage class specifiers. Even you will know C variable storage class. In addition, you will have idea about C storage class and memory. However, do not forget to practise C storage classes with example exercises. You can keep reading to know more about it.

What is storage class in C language?



In C programming language, storage class is scope or visibility of variables. Furthermore, life of

 variables and or functions is storage class. You must remember that storage classes come before 

type. Because type will change them.


Types of storage classes in C programming language

auto storage class in C

The auto storage class is default storage class. It applies to all local variables. However, there is difference between auto and static storage class in C language.
Example program

Define static storage class in C programming language

On the other hand, static storage class will instruct compiler to place local variable in existence. This is for life time of a program. Moreover, destroying it every time is not necessary. Thus, you can make local variables static. In this way, local variables will maintain values between the function calls.
There are many advantages of static storage class in C. Apart from this, you can use static modifier to global variables. Because of this, scope of variable stops at file. This is declared one. Hence, this is another use of static storage class in C.
To explain static storage class in C, you must know one more point. There is another use of static storage class on class data member. Because of this objects of class can share copy of member.
Example program

Explain register storage classes in C with examples

There are many advantages of register storage class in C. With register storage class, you can define local variables. You may store these variables in register class specifier than RAM. It means variable will have maximum size. Moreover, it is equal to register size. However, it cannot have unary & operator.
You must use register storage class specifier in C only for variables. Examples can be counters. As these variables require quick access. Finally, storage of variables depends on implementation and hardware restrictions.
Program example

Define extern storage class in C

You use extern storage classes in C in many ways. You can use them to refer global variable. Moreover, this variable is visible to all program files. A few points are necessary when you use extern storage class specifier in C. It is that variable will not initialise. But it will point variable name at storage location. This location is the place where definition of storage class was given.


Example program
So, you understood difference between static and extern storage classes in C. Even C multiple storage classes in declaration specifiers topic is clear. However, do not forget to practise C storage class and memory examples. In next chapter we will check Operators in C.



C programming Constants and literals



Constants and literals in C programming language is topic we discussed in detail. Here, you will know difference in constants and literals in C. You can also check literals and constants in C with examples.  But you should also practice examples for C constants. Moreover, there is a link to Variables in C as well.
Therefore, it is better if you have idea about Data types in C. As this will help you to understand constants in C language.

What are constants and literals in C programming language?

In C programs, constants mean fixed values. In addition, programs will not change during execution. Moreover, these values are literals only. These constants may be of basic types. Moreover, constants are similar to variables. But the only difference is that you cannot modify these values. This rule applies after defining them.

Integer literals in C programming language

Integer literal may be octal, decimal or even hexadecimal constant. Moreover, prefix will indicate base or even radix. 0X or 0x is for hexadecimal. 0 is for octal and there is nothing for decimal. There is also suffix for integer literal. And it is combination of L and U. Here, L stands for long and U is for unsigned. Moreover, suffix can either be in lower or uppercase.
Program example

Character constants in C programs

Single quotes enclose character literals. You can store them in simple variable of char type. In addition, these can be plain characters or escape sequence. Even universal characters are of this type. However, some characters in C have special meaning. This is especially when there is backslash in front of them.
Example program

Floating point literals in C programs

Even floating point literal will have integer part. In fact there is decimal point, exponent and fractional part as well. You may represent floating point literals in C in exponential or decimal form. Finally, e or E introduces signed exponent.
Program example

What are string literals in C?

Double quotes enclose string literals or constants. In addition, string has characters. And these characters are similar to the character literals. These similarities are escape sequences, plain characters and the universal characters. You may even break long lines in to many lines. You can do this by using string literals.  However, separating them with White spaces in C is also possible.
Program example

How to define constants

You can use #define pre-processor or const keyword to define constants. You can check below examples to know how to do this.
Example programs.
Thus, you now know constants in C language with examples. Even literals in C with examples are clear. However, do not forget to practice constant string literals in C programming language examples.
Constants and literals concept will help you in further chapters. Therefore, start practicing exercises here. Because it will be helpful in loops, functions in C programs.




C programming data types



C data types format specifiers is important topic. These data types in C is easy topic as well. You will use these in most programs. You will use data types in C to refer extensive system. This system will declare either functions or C variables. In addition, variables and functions can be of different types. You will learn more about data types in C with examples here.
You must remember that variable type determines space. This space is about storage. Moreover, it interprets bit pattern stored. However, these C data types have different classification. Keep reading to know more about them.


Name of data typeDescription
Basic TypesThese are arithmetic types. Classification is as follows: integer types and the floating-point types
Derived typesPointer, Array, Structure, Function and Union types
Enumerated typesThese are also arithmetic types. They define variables. These can assign certain discrete integer values in program
The type voidType specifier void will state that there is no value
Array and structure types together are aggregate types. You must remember that function type indicates return value of function.

List of standard integer types, storage sizes and value range

TypeValue rangeStorage size
unsigned char0 to 2551 byte
char-128 to 127 or 0 to 2551 byte
signed char-128 to 1271 byte
int-32,768 to 32,767 or -2,147,483,648 to 2,147,483,6472 or 4 bytes
unsigned int0 to 65,535 or 0 to 4,294,967,2952 or 4 bytes
long-2,147,483,648 to 2,147,483,6474 bytes
unsigned long0 to 4,294,967,2954 bytes
short-32,768 to 32,7672 bytes
unsigned short0 to 65,5352 bytes

sizeof operator in C

You may use sizeof operator in C. This will get exact size of variable or type. In addition, sizeof(type) will yield storage size of object. Or even the type in bytes.
Example program

Void type in C programming language

Name of the typeDescription
Function returns as voidYou must remember that many functions in C do not return any value or return void. Additionally, function with no return value has void as return type. Example void exit (int status);
Pointers to voidA pointer of type void * will represent address of object. However, it will not be type. Example is memory allocation function void *malloc( size_t size );
Because here, it will return pointer to void. Moreover, you can cast it to other data type
Function arguments as voidApart from above two, there are other functions in C. These functions do not accept parameters. So, remember that a function with no parameter can never accept void. Example is int rand(void);


Floating-point type in C programming language

Name of the TypeValue rangeStorage sizePrecision
float1.2E-38 to 3.4E+384 byteIt is 6 decimal places
long double3.4E-4932 to 1.1E+493210 byteHere, there are 19 decimal places
double2.3E-308 to 1.7E+3088 byteIt is 15 decimal places
Header file float.h will define macros. Macros in C language allow you to use values and real numbers in programs. Also know about Operators in C.
Example program

















C programming Variables



Variables in C language is topic for today. Here you will know variable declaration rules in C. 

Moreover, you can check variables in C examples. However, remember to understand rules first.

 These are rules for declaring variables in C.



What is variable in C?


Variables in C definition is simple. Because variable is name for storage area. Here program will

 manipulate. In addition, variables in C have type. This type tells you layout and size of memory of

 variable. You may even store range of values. Finally applying operations to variable is easy.


Name of variables in C language


Letters, digits and underscore makes variables names. You must know that C is case sensitive

 programming language. Therefore, upper and lowercase characters have different meanings.

 However, name of variable must start with letter or underscore.



Name of the TypeDescription
floatThis is single-precision floating point value
voidIt will represent absence of type
charIt is single octet that is one byte. In addition, this is integer type
doubleThis type is double-precision floating point value
intFinally, this type is natural size of integer for machine



Know variable definition in C programming language


Variable definition will tell compiler how much or where should they create storage. It also 

indicates Data type in C. In addition, there will be one or more than one variable in this list.



Program example

Even initialization of variables is possible. It happens during declaration. You must remember that 

initializer will have equal sign. Moreover, after this there will be constant expression.


Example program

In fact if there is definition without initializer. Then variables, which have static storage duration, will

 initialize with NULL. This is initial value for all undefined variables.

How to declare variable in C



If there is variable declaration then compiler is happy. Because compiler can go forward with the

 process. Moreover, compiler requires variable declaration when linking program. It is also useful

 when you use multiple files. Even you can define variables.


However, you must not forget to use ‘extern’ keyword. As this declares variable at other places. Finally, declaration of variables in C may happen multiple times. But you can define it only once. This happens once in file, block of code or function.
Example program


Rvalues and Lvalues in C language

In C programming language, you will come across two expressions. These are lvalue and the rvalue.
Lvalue are expressions referring to memory location. This may appear at right or left hand side of assignment. On the other hand, there is rvalue. Rvalue is for data value stored at address in memory. In addition, rvalue can never have value assigned to it. Hence, rvalue is on right hand side of assignment only. And it can never come on left hand side.

Points to remember

  • Lvalues are variables
  • That is why they may appear on left hand side of assignment
  • Whereas numeric literals are rvalues
  • Therefore assignment of these values may not happen
  • Hence they will not come on left hand side
Program example
So, now you know variables declaration rules in C. However, do not forget to practise variable declaration in C example programs. This way you will know about C variables declaration methods. Moreover these relate to Constants in C also. To know how read next article.















Friday, June 29, 2018

C programming basic Syntax




C syntax program is very easy. You will know what is syntax of C programming language. In addition, 

you will know tokens in C language. Even White-space in C programming language has been 

discussed here. You must also remember that you practice C syntax example exercises.


Practice all the exercises here to know syntax of C programming language. Keep reading to know more.


What are tokens in C programming language?



C program has tokens. These tokens can be keyword, string literal and identifier. Even constant and symbol are tokens.


Comments in C program



In C program, comments help text. Moreover, compiler ignores these texts. You must also know how 

these comments start and end. Comments start with /*. While they end with */. You must also 

remember a few more points. Firstly, you cannot write comments in comments. Secondly, they will

 never occur in character or string literals.


What are semicolons in C?


Semicolon is statement terminator in programs that you write in C. It means that all statements will 

end with semicolon. In other words, it is end of logical entity.

C program identifiers


You will use C identifier to identify variable or functions. You can even identify user-defined things.

 In addition, identifiers begin with A to Z or a to z. Plus, underscore ‘_’ can start as identifier. However, 

letters, zero’s or digits (only from 0 to 9) come after identifiers.

Note: 


C will never have punctuation characters. Therefore, in identifiers you will not have $, @, %. Another 

aspect is that C is case sensitive programming language. Hence, Adam and adam are different 

identifiers in C.

Keywords in C



In C, you can check reserved keywords. These reserved keywords will not use as variables, constants or other identifier names.




List of keywords in C programming language


constforsignedvoid
dointstruct_Packed
breakenumregistertypedef
caseexternreturnunion
autoelselongswitch
charfloatshortunsigned
defaultifstaticwhile
doublegotosizeofcontinue
volatile





Whitespace in C programming language


C compiler ignores blank line. This line has whitespace. And there can be a comment there. There are

 C whitespace rules. These rules apply to C whitespace characters. In addition, in C whitespace

 means blanks, newline characters, tabs or even comments. This whitespace character function will

 separate statements.


Therefore, compiler identifies element in statements. C whitespace characters copy should be there.

 This has to be between int and age. In this way compiler will differentiate them. Finally, C

 whitespace code will increase readability.