C- TOKENS

C- TOKENS


Today I am here with my new Technical Learning, hope you all might get benefited from it

Hello folks!....

Hope You All are having good Reading

Below I'm sharing my complete learning regarding Technical Concept (C Language). Have a glance on this and enjoy your reading.

C Tokens the smallest individual words we are using in developing a c program are called tokens. They are of different types.

No alt text provided for this image


  1. Keywords: The system predefined/ reserved words are called keywords. Each keyword is having certain meaning and we can't change this meaning. C comes with 32 keywords. Eg:- auto, break, char, case, const, continue, do, default, double, enum, else, for, float, goto, int, if ,long, short, signed, unsigned, switch, while, typedef, register, return, extern, static, void,.....
  2. Identifiers: Names of variables, functions, files, array, pointer, structure,..... Eg: int a; example for variable void sum(); example for function int a[5]; example for array variable name int *p; example for ptr variable name.

No alt text provided for this image

How to download C++ compiler: open any browser. Type download turbo c++ by akki. Download winrar.

Example program:

No alt text provided for this image

Identifier naming rules:

  1. Name should have to start with alphabet or underscore [ _ ]

No alt text provided for this image
No alt text provided for this image

2. Numbers allowed but not at first position.

No alt text provided for this image

3. No special char except underscore.

No alt text provided for this image

4. Spaces not allowed.

No alt text provided for this image
No alt text provided for this image

5. Keywords are not allowed.

No alt text provided for this image
No alt text provided for this image

6. Names are case sensitive. i.e. lower and upper are different.

No alt text provided for this image
No alt text provided for this image

7. Duplicate names are not allowed.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

8. Name may contain up to 32 char and excess char's ignored by the compiler automatically.

No alt text provided for this image
No alt text provided for this image

Constants: Fixed values. we can't change the constant value during program execution. Constant value during program execution. Constant value should be provided at the time of declaration only and further Initializations not allowed.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Eg:

  1. Numerical constants: const float pi= 3.14; const int rollno=1234;
  2. Char constants: const char name[ ]="ravi"; ==> string const char gender= 'M';==> char

String: A group of characters, It is alpha-numeric. i.e. it is collection of alphabets, numbers and special characters. Eg: char city[ ]="Hyd-16";

Note:

  1. One byte should be left for NULL Char [ \0]. Otherwise we are getting garbage values.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

2. String variable size never smaller than the string. Otherwise we are getting error.

3. We can't copy a string into a variable using = operator. For this we have to use strcpy( ) available in string.h

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image


4. We can't compare two strings using == operator. For this we have to use strcmp( ) available in string.h

No alt text provided for this image
No alt text provided for this image

Operators: Operator is a special symbol designed for a particular task [work]. In C we are having 44 operators and 14 separators. Based on no. of operands participating in operation, the operators divided into 3 types.

  1. Unary operator: Require one operand. Eg: a++, a--, +a,-a, sizeof(a),~a, !a,...
  2. Binary operators: Require two operand. Eg: a+b, a-b, a>=b, a!=b, a==b, a<<b, a>>b,...
  3. Ternary/Conditional operator [? :]: It requires 3 operands. Eg: condition ? true part : false part;

Based on the operation, the operators divided into several types.

  1. Assignment operator [=]: It copies the value on its right side into the value on its left. left side operand should be variable. i.e. left side constant value expressions not allowed. String copy not allowed with = operator. Eg; a=10 b=1.2; c='X'; d="abc"; ==>error because of string copy a=b=c=100; 10=20;==> error because of 10 is constant c=a+b; a+b=c;

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

2. Arithmetic operators[ +, -, *, % , /]: They are used to perform mathematical operations. Eg: a+b, a-b, a*b,.............. %- modulus [Remainder]: Eg: 5%2=1

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Note: If divisor bigger than dividend then dividend is the answer .

5.0%2.0==Error

No alt text provided for this image


No alt text provided for this image
No alt text provided for this image

Note: In C & C++ we can't perform floating modulus with% operator. we should have to use fmod() belongs to <math.h>


No alt text provided for this image
No alt text provided for this image

Note: If numerator is negative then result also negative

No alt text provided for this image
No alt text provided for this image

Note: Any number%10 gives the last digit.

/ ==> division [Quotient] : 5/2=2[int/int=int] 5.0/2=2.500000

Note: Any one or both are float answer also float 5/2.0=2.500000 5.0/2,0=2.500000 (float)5/2=2.500000[explicit type casting] int a=2.3; =>Output => a=2[implicit type casting] 5/(float)2=2.500000 (float)(5/2)=2.000000

No alt text provided for this image
No alt text provided for this image

Note: In division any one operand is negative then result also negative. Both are positive/ negative then result is positive.

No alt text provided for this image
No alt text provided for this image

Note: Any n/10 removes the last digit.

No alt text provided for this image
No alt text provided for this image

Method 1: write a program to print a 3 digit no in reverse order without using loop. Eg: 123 as 321

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Method 2:-

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Relational Operators [ == (Comparison), <, >, <=, >=, !=(not equal)]:They are used to check the condition or expression is true or false. If condition true always it return 1. Condition false it return 0.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Logical Operators:

To combine two or more expressions we are using logical operators\

  1. && - and
  2. | | - Or
  3. ! - not [negation]

Truth Tables:-

No alt text provided for this image

  • !true= false
  • !false =true

Note: in C other than ) anything is 1 i.e. true.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image


3.Increment / Decrement / modify Operator[++/--]: They are used to increment or decrement a variable value by 1. Eg: int a=8; a++; ==>a=a+i ==>a=9 int a=2; a-- ==> a=a-1;==> a=1

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image


No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Note: Until assignment to any other variable, pre & post operations are same.

No alt text provided for this image


No alt text provided for this image
No alt text provided for this image
No alt text provided for this image


No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image


No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Note: we can't perform ++/ -- on expressions.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Output: a=5, b=5, c=5, d=1.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Note: In && operation when left exp false right exp not checked.

No alt text provided for this image


No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Note: In || operation when left exp true then right exp not checked.

No alt text provided for this image
No alt text provided for this image

Note: we can't perform inc/ decr on constants/ expressions.

No alt text provided for this image
No alt text provided for this image

Note: In printf() execution order is right to left.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

a=5 a= a++ + ++a; priority: ++a,+,=,a++ 1. ++a ==> a=6; 2. a= a+ a==>a=6+6 3.a=12 4. a++ ==> a=13

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Compound assignment operator / short hand operators:-

Here assignment operator used with other operators as follows. Assignment operator have the least priority. += , -=, *=, %=, /=,<<=,>>=,~=,.....

int a =2; a+=5; i.e. a=a+5=>a=7 int b=20; b*=5; i.e. b=b*5=>b=100 float c=5; c/=2; i.e. c=c/2=> c=2.500000

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

NOTE:- Here = have more priority than , operator.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Address Operators:

  1. & => Address of the variable/ value.
  2. * => Address of another variable [pointer].

No alt text provided for this image
No alt text provided for this image

Sizeof() operator: It returns the no of bytes taken by a variable / data type /value.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Note: Integer can't convert to float

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

BITWISE OPERATORS

Bitwise operator's works on bits. Turbo-c is a 16 bit compiler. Due to this bitwise operations are limited to 16 bits only [ 2^0 to 2^15]. Bitwise operators operate integer type values only. We have to calculate only the on bits[1].

When the first bit[sign bit] is 1 then the number is negative and it is 0 then the number is positive. They are very much used in system software development.

Note: Bitwise operator is low level feature.

C-language supports following bitwise operators.

&- Bitwise AND | - Bitwise OR ^ - XOR==> Exclusive OR ~ - Compliment operator << -Left shift operator >> - Right shift operator

&- Bitwise and: In this bits are 1's then result bit is 1. Otherwise result bit is 0. Eg: 25 & 15 =9

No alt text provided for this image


| -Bitwise or: In this both bits are 0's then result bit is 0. Otherwise result bit is 1. Eg: 25 | 15 =31

No alt text provided for this image

^ - XOR [Exclusive OR]: In this both bits are same then result bit is 0. Otherwise result bit is 1. Eg: 25 ^ 15= 22

No alt text provided for this image

~ - Compliment operator: In compliment operation the bits are complimented i.e. 1's become 0's and 0's become 1's. Due to this +Ve no. become -Ve and -Ve become +Ve. Eg:~25 => -26

No alt text provided for this image

Note: When starting bit is 1 given no is -Ve. Eg: ~ -25 ==> +24

No alt text provided for this image

<< - Left shift operator: In left shift, the specified no. of bits are deleted from left side and the same no. of zero added on right side, In left shift operation, most probably the value is multiplied with 2 that no. of times. Eg: 25<<1=50, 25<<2=100, 25<<15=-32768, 25<<16=0

No alt text provided for this image
No alt text provided for this image

Note: When stating bit 1 no. is negative.

<< - Right shift operator: In right shift operation, the bits are moved to right side i.e. the specified no. of bits are deleted from right side and same no. of zero's are added left side. Due to this always the number is divided with 2 that no. of times. Eg: 25>>1=12, 25>>2=6, 25>>3=3, 25>>4=1,25>>5=0.

No alt text provided for this image
No alt text provided for this image


No alt text provided for this image
No alt text provided for this image

Thankyou For Reading!

Published by:?Sakshi Agrawal

Date?:?February 17,2022

要查看或添加评论,请登录

Sakshi Agrawal的更多文章

  • SpringBoot Annotation

    SpringBoot Annotation

    Hello, to my all readers, Hope you all are enjoying your daily learning. Among my daily updates, Today I have come up…

  • Inner V/s Sub Classes In Java

    Inner V/s Sub Classes In Java

    Hello, to my all readers, Hope you all are enjoying your daily learning. Among my daily updates, Today I have come up…

  • What’s the variance amid an Abstract Class and Interface in Java?

    What’s the variance amid an Abstract Class and Interface in Java?

    Greetings to all my esteemed readers! I trust that each of you is enjoying a delightful reading experience. Please find…

  • Bitbucket

    Bitbucket

    Hello to my all Readers!..

  • Microservices

    Microservices

    Hello to my all Readers!..

  • My New Journey

    My New Journey

    Hello to my all Readers, Hope you are enjoying your reading. It's being quit long time I haven't shared the thoughts…

    2 条评论
  • Programs on operators

    Programs on operators

    Hello to all my Reader As you see my daily updates regarding my new work as a Python faculty in CCCGadarwara [Christ…

  • Python Session Overview

    Python Session Overview

    Hello to all my Reader As you see my daily updates regarding my new work as a Python faculty in CCCGadarwara [Christ…

  • Python Session Overview

    Python Session Overview

    Hello to all my Reader As you see my daily updates regarding my new work as a Python faculty in CCCGadarwara [Christ…

  • Python Session Overview

    Python Session Overview

    Hello to all my Reader As you see my daily updates regarding my new work as a Python faculty in CCCGadarwara [Christ…

社区洞察

其他会员也浏览了