C – Basic

 

 



Character Set

  • Alphabets – A, B, …. Y, Z a, b, …. y, z
  • Digits – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • Special symbols – ~ `! @ # $ % ^ & * ( ) _ – + = | \ { } [ ] : ; ” ’ < > , . ? /
  • White space – Blank space, Horizontal tab, Carriage return, New line , Form feed.

 



Reserved Keywords

  • auto
  • break
  • case
  • char
  • const
  • continue
  • default
  • do
  • double
  • else
  • enum
  • extern
  • float
  • for
  • goto
  • if
  • int
  • long
  • register
  • return
  • short
  • signed
  • sizeof
  • static
  • struct
  • switch
  • typedef
  • union
  • unsigned
  • void
    • void functions can’t return a value
  • volatile
  • while

Identifiers

  • Rules
    • Should not use keyword as a identifier
    • First letter should be English word
    • May use Uppercase and Lowercase letters
    • Can use _ underscore as a first letter of Identifier
    • Identifiers are case sensitive(below both identifiers are not same)
      • Ab -valid identifier ab -valid identifier
    • Eg:
      • Valid Identifiers
        • Sum
        • basic_pay
        • a1
      • Invalid Identfiers
        • 8a – First letter should not be numbers
        • auto – auto is a keyword

Constants

  • (Two types : Primary, Secondary)
  • When the program execution time constants should not be change their value (A constant is an entity that doesn’t change)

Primary Constants

  • Numeric Constants (Three Types)
    • Integer or fixed point Constant (Three Types)
      • Decimal
        • Decimal constants are 0 to 9 numbers
        • Integer constants are also called as Decimal constants
        • Eg
          • 86 , 94 , -133
      • Octal
        • Octal constants are 0 to 7 numbers
        • First number should be ‘0
        • Eg
          • 0137 , -0567 , 034
      • Hexadecimal
        • Hexadecimal constants are 0 to 9 and A to F
        • First number should be start with ‘0x’ or ‘0X’
        • Eg
          • 0X73A , 0x89FA
    • Real or floating point Constant (Two types)
      • floating points may contain . dot point.
      • Rules
        • Should use 0 to 9 numbers
        • Dot point may come front or back
        • Sign symbols should be put front of the float numbers
      • Eg
        • 537.36 , -158.77
      • Floating points are two types
        • Fractional form
          • dot points are consider as fractional forms
          • Eg
            • -0.567 , .64 , 24.0
        • Exponential form
          • Rules
            • May use mantissa and exponent symbols
            • Should not use .dot point in exponent
            • Should have at-least one digit in exponent
            • Eg
              • 0.2571e-5
                • mantissa – 0.2571
                • exponent – -5
  • Character Constant
    • Character constant are come with two single quotes ()
    • Eg
      • 'A' – (ASCII-65)
      • 'O' – (ASCII-48, EBCDIC-240)
      • 'a' – (ASCII-97, EBCDIC-129)
      • 'z' – (ASCII-122, EBCDIC-269)
      • % – (ASCII-37, EBCDIC-108)
  • String Constant
    • String constant are come with two double quotes ()
    • Eg
      • "ARUN" – Valid
      • "2020" – Valid
      • "A" – Valid
      • "ABC – Invalid
      • 'sum' – Invalid

Secondary Constant

  • Array
  • Pointer
  • structure
  • union
  • enum

 



C Programming Structure

  • Pr-processor Commands
  • Type definition
  • Function prototype – Declare function type and variable passed to functions
  • Variable – We must have a main function in every c programs

 

 


Note : All the programs are run in gnu gcc of linux.


 

Hello World C program

Code

Output : ArunEworld

 

 



Escape sequence

Escape sequence is a character constant or string constants, its a non graphical character or printable.

Escape sequence Notes Example
\a  – alarm character
\b  – back space  
\f  – form feed
\n  – new line  
\r  – carriage return
  • Carriage return is known as cartridge return and often shortened to CR, <CR> or return.
  • It is a control character or mechanism used to reset a device position to the beginning of a line of text.
  • It is closed associate with the line feed and newline concepts.
 
\t  – horizontal tab  
\v  – vertical tab
\\  – back slash
\?  – question mark
\'  – single quote
\"  – double quote
\000  – character representation \xbh – character representation
\0  – nul character

 

FAQ

  • Difference between '/0'  and '\0'  in C programming?
    • ‘\0’ – Null terminator in array

 



 

Data types

  • Data types in any of the language means that what are the various type of data the variables can have in that particular language.
  • Whenever a variable is declared it becomes necessary to define data type that what will be the type of data that variable can hold.
  • char , int , float and double are basic datatype
  • short , long , signed and unsigned are data type modifier (Qualifier)
  • Rules
    • Every variable should have any one of the following data type
Types bit Size Range
char (or) signed char 8 (1byte) -127 to 127
unsigned char 8 (1byte) 0 to 255
int (or) signed int 16 (2byte) -32,767 to 32,767
unsigned int 16 (2byte) 0 to 65,535
short int or signed short int 8 (1byte) -127 to 127
unsigned short int 8 (1byte) 0 to 255
long int (or) signed long int 32 (4byte) -2,147,483,647 to 2,147,483,647
unsigned long int 32 (4byte) 0 to 4,294,967,295
float 32 (4 byte) 3.4E-38 to 3.4E+38
double 64 (8 byte) 1.7E-308 to 1.7E+308
long double 80 (10 byte) 3.4E-4932 to 1.1E+4932

The various general types of data are:

  1. Number type data
    1. Integer Type
      • int
    2. Float type (three types)
      • float
      • double
      • long double
  2. Character type data
    • char
  3. String type data
  4. Boolean type data


Variables

  • When the program execution time variable may be change their value.(A variable is an entity that does change)
  • Eg
    • Sum , average , basic_pay , basic-pay , A0 etc (valid variables)
  • Declaring a variable
    • Rules
      • should be declare datatype of variable.
      • data types name should be declare data type’s
      • if declare multiple variable in single data type, separate each by , operator
      • Every declaration should end with ; semicolon
    • Syntax
      • datatype variable_1, variable_2, .....variable_n ;
      • Eg:
        • int a, b , c; //here a,b, c are integer variables
        • float salary; //here salary is a floating type variable.
    • Use of variable declaration
      • Compiler can allocate a memory when we declared data type variable
  • Variable Initializing
    • Syntax
      • datatype variable_name = initial value;
      • Eg: int sum = 1;
  • Assigning value to Variable (Assigning Operator = )
    • Syntax
      • Variable_name = value; Ex: x = 20;
      • variable_name = variable; Ex: y = x;
      • variable_name = expression; Ex: z = x+y;
  • variable is associated with two types :
    • Data type : int , float , char , double , long , signed , unsigned , etc.
    • Storage class : automatic , static , extern , register
  • Storage class : automatic , static , extern , register
Exercise

Q : Which of the following is not a valid variable name in C?
A. 1 a @
B. a 1 2
C. a b 123
D. a b c 123

Answer: Option A (Explanation: First character must be alphabet).

 

You cannot print (automagically) the type of a variable in C. Variables and their types are only known at compile time.

At runtime, there is no variables (only locations & values) and almost no types:

 



Header files (Two types)

  1. Predefined Header files
    • Syntax : #include<file_name> (Stored in Specified directories)
      • If a header file is included with in < > then the compiler searches for the particular header file only with in the built in include path.
  2. User defined Header files
    • Syntax : #include “file_name” (Stored in Locally saved programs)
      • If a header file is included with in , then the compiler searches for the particular header file first in the current working directory,if not found then in the built in include path.


Command Statements

  • /* Commands */ // Commands in paragraph
  • // commands // command in single line

 


 

Format specifier

  • %i – Can be used to input integer in all the supported format.
  • %c – single character
  • %d – decimal character
  • %e – floating point value
  • %f – floating point value
  • %g – floating point value
  • %h – short integer
  • %i – decimal/hexa decimal/octal integer
  • %ld – long integer
  • %o – octal integer
  • %s – string
  • %u – unsigned decimal integer
  • %x – hexa decimal integer
  • [...] – string which may include white spaces

 



Clear screen (clrscr)


How a negative integer is stored?

  • Get the two’s compliment of the same positive integer.

Eg:

 



 


Little Endian, Big Endian

  • Little and big endian are two ways of storing multibyte data-types ( int, float, etc).
  • Image Link

 

Exerciser : Program to find the machine is little endian or big endian

 

Reference : https://www.geeksforgeeks.org/little-and-big-endian-mystery/

 



 

 

 

 

 

 


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

if you have any queries call us +918300026060 or WhatsApp Dismiss

0

Your Cart

%d bloggers like this: