Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Lecture 3 getting_started_with__c_


Published on

Getting Started with C

Published in: Technology
  • Be the first to like this

Lecture 3 getting_started_with__c_

  1. 1.
  2. 2. Popularity of ‘C’● Robust● Efficient and fast● Portable● Structured Programming
  3. 3. Character Set ● A character can a number, alphabet, or any special symbol to represent informationAlphabets A, B, ….., Y, Za, b, ……, y, zDigits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9Special symbols ~ ‘ ! @ # % ^ & * ( ) _ - + =|{}[]:;"<>,.?/
  4. 4. Constants, Variables andKeywords● A combination of character set’s numbers, alphabets and special symbols forms constants or variable or keywords Alphabets, Numbers and Special Symbols Constants Variables Keywords
  5. 5. Constants● A value that does not change during the execution of programming. Constants Primary Secondary Constants Constants
  6. 6. Variables● Variables in C have the same meaning as variables in algebra. That is, they represent some unknown, or variable, value. x=a+b z + 2 = 3(y - 5)● Remember that variables in algebra are represented by a single alphabetic character.
  7. 7. Keywordsauto double int structbreak else long switchcase enum register typedefchar extern return unionconst float short unsignedcontinue for signed voiddefault goto sizeof volatiledo if static while
  8. 8. Program Structure in C● EACH complete C program is composed of:● Comment statements● Pre-processor directives● Declaration statements● One or more functions● Executable statements
  9. 9. C Syntax and Hello World #include inserts another file. “.h” files are called “header” files. They contain stuff needed to interface to libraries and code in other “.c” files. Can your program have What do the < > more than one .c file? mean? This is a comment. The compiler ignores this.#include <stdio.h> The main() function is always/* The simplest C Program */ where your program startsint main(int argc, char **argv) running.{ Blocks of code (“lexicalprintf(“Hello Worldn”); scopes”) are marked by { … }return 0;} Return ‘0’ from this function Print out a message. ‘n’ means “new line”.
  10. 10. Comment Statements● Formal Comments: /* Comment ….. */● Used for detailed description of functions or operations (for our benefit, not compiler’s).● Can take multiple lines in source file.
  11. 11. Pre-Processor Directives#include -- header files for library functionsExample:#include <stdio.h> Note Space#define -- define constants and macrosExamples:#define e 2.7182818#define pi 3.14159265359 Note Spaces
  12. 12. Declarations● Declarations tell the compiler what variable names will be used and what type of data each can handle (store). ● Example declarations:int a, b, c ;float r, p, q ;double x, y, z ;char m, n ;