c Programming Notes

Please download to get full document.

View again

of 65
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information Report
Category:

Documents

Published:

Views: 398 | Pages: 65

Extension: PDF | Download: 122

Share
Related documents
Description
notes
Tags
Transcript
   Fundamentals of Computer Programming     Downloaded from: http://www.bsccsit.com   C -  Basic Introduction     C is a general-purpose high level language that was srcinally developed by Dennis Ritchie for the UNIX operating system. It was first implemented on the Digital Equipment Corporation PDP-11 computer in 1972. The UNIX operating system and virtually all UNIX applications are written in the C language. C has now become a widely used professional language for various reasons.    Easy to learn    Structured language    It produces efficient programs.    It can handle low-level activities.    It can be compiled on a variety of computers. Facts about C    C was invented to write an operating system called UNIX.    C is a successor of B language which was introduced around 1970    The language was formalized in 1988 by the American National Standard Institute (ANSI).    By 1973 UNIX OS was almost totally written in C.    Today C is the most widely used System Programming Language.    Most of the state of the art software have been implemented using C Why to use C? C was initially used for system development work, in particular the programs that make-up the operating system. C was adopted as a system development language because it produces code that runs nearly as fast as code written in assembly language. Some examples of the use of C might be:    Operating Systems    Language Compilers    Assemblers    Text Editors    Print Spoolers     Network Drivers    Modern Programs    Data Bases    Language Interpreters    Utilities C Compilers When you write any program in C language then to run that program you need to compile that program using a C Compiler which converts your program into a language understandable by a computer. This is called machine language (i.e. binary format). So before proceeding, make sure you have C Compiler available at your computer. Some examples of C compilers are Turbo C and Borland C. C - Program Structure   A C program basically has the following form: Preprocessor Commands Functions Variables Statements & Expressions Comments   Fundamentals of Computer Programming     Downloaded from: http://www.bsccsit.com     Preprocessor Commands:  This command tells the compiler to do preprocessing before doing actual   compilation. Like; #include <stdio.h>  is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation. You will learn more about C Preprocessors in C Preprocessors session. Functions: are main building blocks of any C Program. Every C Program will have one or more functions and there is one mandatory function which is called main()  function. This function is prefixed with keyword int   which means this function returns an integer value when it exits. This integer value is retured using return  statement. The C Programming language provides a set of built-in functions.  printf()  is a C built-in function which is used to print anything on the screen. Variables:  Variables are used to hold numbers, strings and complex data for manipulation. Statements & Expressions: Expressions combine variables and constants to create new values.   Statements are expressions, assignments, function calls, or control flow statements which make up C  programs. Comments:  are used to give additional useful information inside a C Program. All the comments will  be put inside /*...*/ as given in the example above. A comment can span through multiple lines. Note the followings    C is a case sensitive programming language. It means in C  printf   and  Printf   will have different meanings.    C has a free-form line structure. End of each C statement must be marked with a semicolon.    Multiple statements can be one the same line.    White Spaces (ie tab space and space bar ) are ignored.    Statements can continue over multiple lines.   Fundamentals of Computer Programming     Downloaded from: http://www.bsccsit.com   Data Types in C     A C language programmer has to tell the system before-hand, the type of numbers or characters he is using in his program. These are data types. There are many data types in C language. A C programmer has to use appropriate data type as per his requirement in the program he is going to do. Primary data type   All C Compilers accept the following fundamental data types 1. Integer int 2. Character char 3. Floating Point float 4. Double precision floating point double 5. Void void Integer Type   Integers are whole numbers with a machine dependent range of values. A good programming language as to support the programmer by giving a control on a range of numbers and storage space. C has 3 classes of integer storage namely short int, int and long int. All of these data types have signed and unsigned forms. A short int requires half the space than normal integer values. Unsigned numbers are always positive and consume all the bits for the magnitude of the number. The long and unsigned integers are used to declare a longer range of values. Floating Point Types   Floating point number represents a real number with 6 digits precision. Floating point numbers are denoted by the keyword float. When the accuracy of the floating point number is insufficient, we can use the double to define the number. The double is same as float but with longer precision. To extend the precision further we can use long double which consumes 80 bits of memory space. Void Type   Using void data type, we can specify the type of a function. It is a good practice to avoid functions that does not return any values to the calling function. Character Type   A single character can be defined as a defined as a character type of data. Characters are usually stored in 8 bits of internal storage. The qualifier signed or unsigned can be explicitly applied to char. While unsigned characters have values between 0 and 255, signed characters have values from  –  128 to 127. Size and Range of Data Types on 16 bit machine; TYPE SIZE (Bits)   Range Char or Signed Char 8 -128 to 127 Unsigned Char 8 0 to 255 Int or Signed int 16 -32768 to 32767 Unsigned int 16 0 to 65535 Short int or Signed short int 8 -128 to 127 Unsigned short int 8 0 to 255 Long int or signed long int 32 -2147483648 to 2147483647 Unsigned long int 32 0 to 4294967295 Float 32 3.4 e-38 to 3.4 e+38 Double 64 1.7e-308 to 1.7e+308 Long Double 80 3.4 e-4932 to 3.4 e+4932   Fundamentals of Computer Programming     Downloaded from: http://www.bsccsit.com   Declaration of Variables   Every variable used in the program should be declared to the compiler. The declaration does two things. 1. Tells the compiler the variables name. 2. Specifies what type of data the variable will hold. The general format of any declaration datatype v1, v2, v 3, ……….., vn; Where v1, v2, v3 are variable names. Variables are separated by commas. A declaration statement must end with a semicolon. Example : int sum; int number, salary; double average, mean; Datatype   Keyword Equivalent Character char Unsigned Character unsigned char Signed Character signed char Signed Integer signed int (or) int Signed Short Integer signed short int (or) short int (or) short Signed Long Integer signed long int (or) long int (or) long UnSigned Integer unsigned int (or) unsigned UnSigned Short Integer unsigned short int (or) unsigned short UnSigned Long Integer unsigned long int (or) unsigned long Floating Point float Double Precision Floating Point double Extended Double Precision Floating Point long double User defined type declaration In C language a user can define an identifier that represents an existing data type. The user defined datatype identifier can later be used to declare variables. The general syntax is typedef type identifier; here type represents existing data type and „identifier‟ refers to the „row‟ name given to the data type. Example:  typedef int salary;
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks