Programming in C: Remember these points on Datatypes.

‘int’ is 32 or 16 bit long and it depend upon machines. ‘short’ is often 16 bit long. ‘signed’ and ‘unsigned’ may be applied to char. But is plain chars are signed or unsigned ? It is machine dependent. If ‘x’ is float and ‘i’ is int, x = i and i = x both cause conversions.

Specify type correctly:

Please take a nice look to these points,
In C when we write an expression we must ensure that we specified the types correctly.
In an expression even if the left hand side is declared as floating point and the right hand side contain integer arithmetic & constant division, these constant division results the number truncated to integer. So we must represent these constants, as floating point number.
Consider the following expression

(float) a = (b – 18) * 7 / 9 ;

false result will goes to ‘ a ‘
we must write as,

(float) a = (b – 18) * 7 .0 / 9.0 ;


(float) a = (float) (b – 18) * 7 / 9 ;
when talking about the range of int , float it depends on the machines,
16 – bit int that is 2^16 = 65536 , dividing by 2 , 65536 / 2 it equals 32768
that is range – 32768 to 32767 for signed integers.

Consider the following expression,

(n > 0) ? f : n ;

If ‘f’ is float and ‘n’ is int the expression has type ‘float’ according to the conversion rule, not by the result of the condition.


Programming in C: Remember these points on Variables.

Don’t begin variable names with underscore, since library routines often use such names. Upper and lower case letters are distinct. Atleast first 31 characters of an internal name are significant. External names may be used by assemblers and loaders over which the language has no control. The definition of C gurantees that any character in the machine’s standard printing character set will never be negative.

Programming in C: A Small note on Functions.

printf, getchar(),putchar() all are C functions. No fuction can be split between files. ‘main’ function returns a value ,zero if normal termination or nonzero erroneous termination. The function prototype agree with the definition and uses of the function. If the actual arguments are more than the formal arguments, the extra arguments are discarded. And if the actual arguments are smaller than the formal arguments extra formal arguments are initialized to some garbage values. Automatic variables do not retain their values from one call to the next and must be set upon each entry. Any expression may follow a return statement. To assure a high degree of portability between programs a function should generally be coded without involving any I/O operations.Function returns int as default.To assure a high degree of portability between programs, a function should generally be coded without involving any I/O operations.

If a function fails to return a value its value is certain to be garbage. We can also compile three source files using ‘cc’ command which contain the program functions.

$ gcc main.c fun1.c fun2.c

Consider the statement, x = function1() + function2();

Here the order in which the calculation, function1() may be evaluated first or function2() may. C cannot specify such an order.

Programming in UNIX Environment : Commands – echo, rm, whoami

Take a look to the following UNIX commands.
who am i -This command shows your user name,teletype,date and time.

whoami – Shows only user name.

In UNIX systems,

parent directory is denoted by ‘..’
current directory is denoted by ‘.’

rmdir – for remove a directory. It removes only empty directories.

About shell :

When we type the commands it goes to the shell.It is an ordinary program.

cat c* //prints all file that begins with c.

when * occurs shell takes it and it means any string of characters. Note the * is not the property of the cat command.

The echo command lists what we type.

echo word

echo ch* //lists all begin wth ch.

echo * //lists all.

rm * – removes all.

rm *.text – removes all with .text.

pr r[1234]* // prints all that begin wth r and followed by 1,2,3 or 4.

rm te[a-z] //removes all files starting with te and followed by a lower case.

You cannot make up new files using pattern matching.

ls \? or ls ‘?’ loses its meaning.

echo * // prints all.

We can redirect the output by using ‘>’. Take input from a file by using ‘>’.

ls > filelist

pr -3 <filelist // print ls in three columns.

cat file1.c file2.c > file3

cat file4.c >> file3.c

grep num.c <filelist