Tuesday, July 8, 2014

Operator Precedence in Arithmetic and Comments in C programming

Hierarchy of Operations: The computer scans an expression from left to right and performs only one operation at a time. The order in which various operations are performed is referred to hierarchy of operations

Order of evaluation
Arithmetic Operators
+ -

  1. Library function used in the expression are executed before the precedence is executed.
  2. Parenthesis may be used to overcome the precednce order. When parenthesis are used , one written on the left side will be executed first. E.g (a+b) - (a-b) , so (a+b) will be executed first
  3. When nested parenthesis are used, the innermost parenthesis will be executed first. 
e.g ((a+b) * c) so here (a+b) will be executed first.

Have a look at this video for more information

Sunday, July 6, 2014

Arithmetic Operators and scanf() to get user input in C programming

Arithmetic Operators are used to perform Arithmetic operations in C programming.

+Addition5 + 27
-Subtraction5 - 23
*Multiplication5 * 210
/Division5 / 22
%modulus operator to get remainder in integer division5 % 21

Remember when two operands (5 and 2) are integers, the result obtained is an integer. To obtain real value in the result, at least one of the operators must be float or double . Consider the following example.

5.0/2.0 or 5/2.0 or 5.0/2 will produce the result 2.5 .

Also consider the following examples to get the remainder on modulus operations.

7 % 4 produces the result 3
4 % 10 produces the result 4

An expression consisting of numeric variables, constants and arithmetic operators is called Arithmetic expression. The value obtained by evaluating an arithmetic expression is always numeric , i.e. integer or float/double type.

for b^2 - 4ac the equivalent expression in C would be b*b - 4*a*c

Please have a look at this video

scanf() function 

scanf() function is used to read/input values of the variables using the standard input device (keyboard)
for example:

scanf("format string", &v1, &v2, ...., &vn);

where v1, v2,...., vn are variables whose values are to read from keyboard, (basically these are addresses but we will see that later)

"format string" is the control string which represents the format specification refer the below Table

The symbol '&' Ampersand represents the memory address where the variable value is to be stored.


scanf("%d %f", &a, &b);


scanf("%d %d", &a, &b);


scanf("%c %c", &a, &b);

When these functions are executed , the computer will wait for the values of the variable listed in scanf which are to be entered using the keyboard.

Format Specifiers
Data Type
Represents a decimal integer value
Represents a unsigned integer value
Represents a unsigned octal value
Represents a unsigned hexadecimal value
Represents a decimal integer value
Represents a decimal integer value in decimal or exponential form
Represents a single character value
Represents a string of value of characters

%hd, %ld, %lf are used for short int, long int and long double respectively.


Thursday, June 26, 2014

Google Maps recorded image of UFO in Trout Creet, Montana USA

Hello all , I thought I must share this to all the people. I saw a video today on YouTube about the recent traces of UFO in Trout Creek Montana USA recorded as satellite images by Google Maps.  So I tried to confirm myself looking inside the Google Earth/Maps and the results are very interesting.

1) Open the Google Maps and Searched for Trout Creek Montana USA.

2) The I zoomed to this position please note down the coordinates.

3) Drag the Street view (Person Icon) from the right hand side vertical toolbar of Google Earth

4) Now this would enable Street view in Google Earth/Maps. and you would be able to see something like this.

5) Now Move up to the sky and within a certain range you would find an Orange Saucer like structure and this might be UFO.

6) Zoom it more and you would be able to see a perfect shape that has been described by many discoverers, wanderers, scientists and people around.

So this is a trace and this object captured unintentionally might be the UFO. Keep looking at the sky sitting at your home, may be you can see UFO with naked eyes.


Saturday, June 21, 2014

Puzzles, Interaction and Games Development using Scratch for kids an initiative by MIT

In this growing technological world, education has also changed a lot with more competitiveness and everyone looking to solve the world's toughest problem using Computations. Computer Science has a very important aspect of communicating with Machines a.k.a Computers , that is Computer Programming. Computer Programming can be done using Machine Language ( consisting of 0's and 1's) , Assembly Language ( consist of Mnemonics like ADD 1001,1002) and High Level Programming Language ( offers set of keywords, operators and syntax).

In the coming age we want our next generation to be ready to deal with the basics of what we are working as a professional, but this learning should be done with much more fun and fascination in it. Therefore Scratch project is made by MIT to teach the basics of programming , using the attachment of puzzle pieces, therefore you can build Puzzles like tic-tac-toe or interactions like When Johnny was called by dad what does Johnny answered ( i.e. "Yes papa"), then again after Johnny's answer what does his father replied.

You can find a very addictive environment of game development in scratch . I have made an Interaction and a small game, that would let you know the goodness and ease of scratch very well.

Please share this great app with your little brothers and sisters so that they can learn things well and support rapid growth of Humans :D.

My Scratch Interaction : As there is Football fever all round.

and my game Shootatsight, shoot the creatures come in your way.


Monday, June 16, 2014

Constants and Variables in C programming


Any unchanged value in a program during the program execution is called constant. Following are the constants in C language.

a) Numeric Constants

There are two types of numeric constants.

(i) Integer constant: An integer constant is a signed or unsigned whole number.

Example:         -25       +350        42

C language supports an integer constant in octal (base 8) , decimal (base 10) and hexadecimal (base 16). The default number system followed in C language is decimal (base 10).

An octal number is preceded by zero (0) and a hexadecimal number is preceded by 0x or 0X.


Octal constant
Hexadecinal constant

(ii) Real or floating point constant: Any signed or unsigned number with fractional part is called real or floating point constant. A real constant can be written in decimal or exponential form.


Decimal Form                 0.254         +342.0          -3.15

Exponential Form           0.218e6      0.42e-32       -1.0e12
(0.218e6 means --> 0.218 x 10^6 and so on for all)

b) String or Character constant

Any string of characters enclosed in apostrophes or quotes is called string constant or character constant. There are two types of string constants.

(i) Single character string constant: Any letter or character enclosed in single apostrophe is called single character string constant.

Example:             'y'      '$'       '+'

(ii) String of characters constant: Any string of characters consisting of letters, digits and symbols enclosed in double quotes is called string of characters constant.


"Total value is"
"Indore - 452 009"
"Average= "


A variable is an identifier or a name which is used to refer a value and this value varies or changes during the program execution. A variable is written with a combination of letters , numbers and special characters _(underscore) with the first letter being an alphabet. Maximum of 31 letters can be used to write a variable.

Example: x , fact , c22 , total_value 

Important rules while writing a variable in C 

  • Upper and Lower case alphabets are taken differently, so the variables SUM and sum are referring to different values.
  • No special characters other than underscore ( _ ) are permitted.
  • Some C compilers will not accept more than 8 characters. So it is a good practice writing a variable with few letters which makes it also convenient to write and use.
  • All variables used in a C program are declared with appropriate data types before the variable is assigned any value.
  • Reserved words cannot be used as variables.
Variable Declaration

Variables used in C program are declared with appropriate data types. C language permits the used to assign initial values to the variables while declaring them.

Basic Data Types

There are four basic data types in C language. The Bytes Occupies in the RAM is totally dependent on the Compiler specification.

Data TypeBytes occupied in RAMValue rangeValue range in decimal
char1 byte to  – 1-128 to 127
int2 bytes to  – 1-32768 to 32767
float4 bytes to  – 13.4e-38 to 3.4e+38
double8 bytes to  – 11.7e-308 to 1.7e+308

The value range is calculated from the number of bits occupied by the data type. For example, int uses 2 bytes, i.e.16 bits from this 1 bit is taken for sign (- or +). So the range is expressed as  to  - 1 . 

charRefers to character. It can hold one letter/symbol. char in C language is associated with integers to refer a letter/symbol as per ASCII (American Standard Code for Information Interchange) which has assigned integer value for all letters/symbols used in programming.
intRefer integer. It can hold a signed and unsigned whole number within the specified range.
floatRefers floating point or real number. It can hold a real number like 3.174813 or 4.5e6 with six decimal digits in decimal or exponential form. A float number using 6 decimal digits is called a single precision number.
doubleAlso refers to floating point or real number. It can hold a real number in double precision. A double precision number uses 12 decimal digits like 3.412587632156 or 4.52145342148e12.

refer to C programming diary on my Blog: C programming Diary

To quickly start programming in C, we need to understand about Constants and Variables in C programming. We would be using Constants or Variable for our data. So I have prepared a slide on Slideshare about Constants and Variables please have a look.

For those who want a better explanation over the following slide please refer to this video this might help you understanding about Constants and Variables.

Now as you have known much about Contants and Variable , let us have a look at the simple program to use them.

also there should be a defined naming of a variable please do watch this one.


Fundamentals of C programming

Characters used in C

Uppercase letters A to Z
Lowercase letter a to z

0 to 9

Special characters
+ plus, comma< less than
- minus. full stop> greater than
* asterisk; semicolon= equal to 
/ slash: colon( open parenthesis
\ back slash' apostrophe) close parenthesis
% percent" double quote[ open bracket
| vertical bar& ampersand] close bracket
~ tilde# hash{ open set bracket
? question mark$ dollar} close set bracket    
! exclamation mark    ^ caret_ underscore


An identifier is a name having a few letters , numbers and special character _(underscore). It is used to identify a variable, function, symbolic constant and so on. An identifier can be written with a maximum of 31 characters. It is a good practice to have identifiers with few letters; less than 8 letters is commonly followed with the first letter being an alphabet.

x2 , sum  (can be used as variables)
calcu_avg , matadd   (can be used as function names)
pi, sigma  (can be used as symbolic constants)

Keywords or Reserved Words

C language uses the following keywords which are not available to users to use them as variables/function names. Keywords are always written with the lower case letters. Some C compilers use more keywords which they include in their documentation or manual pages.


C program has some punctuation marks, keywords and operators as the smallest individual units and are referred to as C tokens. Following six types of tokens are used in C language.

C tokens
auto, break , etc
-25 , 3.15 , etc
calcu_avg , sum , etc
String literals
“Total Amount Rs. ”     
+ , - , * , etc
' ; :

refer this page of my blog: C programming Diary

C programming can be used to its best once you know the fundamentals of C programming. So please have a look at the fundamentals of C programming in the attached slideshare slide. The following slide would make you understand about the C programming Language.

Well some of those who want a better narration over the above slide may refer the following video please have a look.


Thursday, June 12, 2014

C Compilers for your operating system

C is a compiled language , so after writing your program you need to compile your program from appropriate C compiler residing in your system and then it produces the executable and you run this executable to see your program working.

In the following post I will discuss about the Compilers of the 3 most widespread operating system Mac, Windows and Linux.

  1. GCC : GCC is GNU Compiler Collection which is open source free to use and distribute, this is for those who do not see paying for compiling the C programs at the beginning as a better option. This is also good for the aspiring open source developers, thinking of contributing and making a mark in open source development. supported well with Unix/Linux and Mac OS X, run well with a bit more effort on Windows.
  2. Microsoft Visual C++: Microsoft developed the following Compiler to compiler both C and C++ program using this. It is a commercial product but it free version is available to make your hands dirty with the development. (Good for Windows Operating system and supported by Microsoft so no worries of bugs and undesired working of the compiler).
  3. Clang: Clang is also a good option as it is an open source compiler and has lots features , It compiles fast , GCC compatibility and simple and hackable code base. The Open Source developer can also have a look at its source. Similar to GCC Clang also supported well with Unix/Linux and Mac OS X, run well with a bit more effort on Windows.
  4. Turbo C: Turbo C is and old option but a good one as it is good with the command line application with Turbo C version 2 and 3 and also good GUI environment for coding , running and debugging C and C++ programs. The command line application are very good to work with MS-DOS operating systems and GUI applications are good to work under Windows Operating systems.

Here is one short video for the users using first time to compile a C program in Linux/Unix based operating system. In this video I have used ubuntu but you can use GCC on any Unix like operating system the command can be used with name 'cc' or 'gcc'.

$ gcc hello.c
/* This will generate an output file named a.out in current directory */
$ ./a.out
/* This means executing the output file from the current directory ('.' represents current here)
and this file thus made by the user this is why it holds execution responsibility from the user itself

with just a little effort of knowing the commands better one can use GCC even better. like we do not want our executable to be named weird 'a.out' so we can explicitly give it a different name using the command with -o flag.

$ gcc hello.c -o hello
/* This will generate an output file named hello in current directory */
$ ./hello
/* This means executing the output file from the current directory ('.' represents current here)
and this file thus made by the user this is why it holds execution responsibility from the user itself

In case you do not even want to run using 'cc' or 'gcc' with flags to get executable of your choice. You can also use the MAKE. MAKE identifies which part of the large compiler needs to be recompiled, thus It prepared the compiles files and generate a proper executable code. MAKE can be used to compile C programs as well.

$ make hello
/* Note: do not use extension of the file to be compiled just use the base name.This will generate an output file named hello in current directory */
$ ./hello
/* This means executing the output file from the current directory ('.' represents current here)
and this file thus made by the user this is why it holds execution responsibility from the user itself