Friday, October 25, 2019

C Language Basics

In this tutorial let's learn about basics of C programming language. Theory and practical both play key role in the learning process.
                

Programs/Applications need inputs to produce output.
  • char 1 - a single character.
  • int 2 or 4 - integer: a whole number.
  • float 4 - floating point value: ie a number with a fractional part. 3.14
  • double 8 - a double-precision floating point value. 5678.899999
  • void - Valueless.
Derived Data Types:
  • Arrays
  • Pointers
  • Structures
  • Enumeration

Escape Sequences in C:

Escape Sequence   Meaning
            \t                 Horizontal Tab
            \n               New line
            \'                Single quote
            \"               Double quote
            \?               Question mark
            \\                Backslash

Keywords in C 

Meaning is already defined by Compiler

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

Wrong way of usage:

int if;  //wrong

Note: Keywords cannot be used for creating variable and function names.

Reading Values from Keyboard in C

  • We use scan statement to take input from the keyboard. We can take one or multiple inputs using one scanf statement. 

Rules for Creating Variables:

  • Should start with alphabet or an underscore only. int abc; int ABC;
  • No spaces allowed.
  • Only _(Underscore is allowed to use).
  • keywords cannot be used as variable names.
  • Case sensitive.

scanf in C 


Explanation: 
scanf(“format string”, argument list);

Example:
int a=2;

int a;
scanf("%d",&a);

int a,b;
scanf("%d%d",&a,&b);

"For Loop" in C: 

"For Loop" in C: Initially it looks difficult, but after a while it will be the one of the common thing that you use in every program or application.
Let’s see how and why in my words!!!!!
To print my name the simple code is here:
  #include 
  int main()
  {
    printf("Kirthi");
    return 0;
  }


Output: Kirthi


Let’s say if I want to print my name(Kirthi) for 100 times, then I should write printf statement 100 times.


Or I should mention my name 100 times in the printf statement.
To simplify this, we need to use of “for loop”.


  #include<stdio.h> 
  int main()
  {
    for(int i=1;i<=100;i++)
    {
      printf("Kirthi \n");
    }
  return 0;
}
Output:
Kirthi
Kirthi
.
.
Kirthi(100 th time).


In above example for loop iterates 100 times because of the condition that we've specified. To make program smaller, to reduce lines of code for loop is used.

Tips For Improvement!

How to overcome Laziness?

It is a state where you cannot think⊂ and do as per your capability. Laziness causes mental and physical disorder if you won't react to it initially. Though it is not a serious disease which can be treated but it requires motivation to overcome. Focus on important things that you must accomplish. Organize your time properly in a day wise or weekly. Understand what you're thinking inside and change the way you think. Try to set smaller goals initially and work to achieve it. Consider this is the right time to break the silence inside you and think you can be a successful. Action is required for all your motivations in you. Obviously every step taken is really a beneficial for you.

  • Its directly not a problem or disease.
  • Requires motivation.
  • Focus on important things.
  • Organize your day properly.
  • Analyse your self-talk.
  • Break the silence, start thinking that you can do.
  • Every step taken is beneficial for you.

How to be active every moment?

Think present and live in reality, do not dig into past unnecessarily. The moment's which went wrong earlier would come to your head the moment you're alone and upset, so be alert control your emotions keep yourself calm and focus on something else. Listening to music would keep you active, prepare a playlist a role it whenever you feel your down.

How to say no without hesitation?

Be strong and say confidently that you oppose certain things without any second thought. Try to explain points that you think are correct in your perspective. Hence time will play key role so be sure of yourself. If you hesitate then you've certainly invited problems and you have to face the consequences of it.

How to improve yourself?

  • Be early at work
  • Wear formals
  • Look  cool
  • Set your goal
  • Be a performer
  • Wish your team mates with smile
  • Make right decisions
  • Think before you speak anything
  • Don't involve in unnecessary discussions
  • Read and respond to emails on regularly intervals
  • Learn more

How you should deal with your Manager?


  • Do your job(Implement accurately the responsibility that assigned to you).
  • Communicate all the important/key information by Mail, becomes formal.
  • Always speak in formal language(official), avoid speaking in regional language.
  • If you feel your Manager is arguing on irrelevant issues by holding grudges, just ignore them.
  • Do not disclose it with other team members whatever is happening in between you and your manager.
  • Pick right time to report it to higher authorities with right reasons possibly with proofs for what you point out.

Do not take resignation decision until you have an excellent offer in your hand. The end is not the solution for problems, any team any company would have issues, finding out the ways to overcome is important rather quit.

What role does your health play in your career?

A famous saying "Health is Wealth" is what everyone have to recollect at least once in a day. If you're not doing good then you can't be creative, that's it. Eat on time, eat good food, treat your body well, replacement or repair to any organ is painful and extremely costlier, finding the way to overcome from any health disorder is highly difficult. The first preventive step is to avoid eating foods that has too much fat in it especially the junk one's. Start your day with a couple of glass of water, prefer light warm, ensure you drink a minimum of two to three liters of water in a day. Water flushes away most of the junk that exists in your stomach and keeps it as much as calm as possible. On the other hand too much water can upset your stomach and you may have to go to wash room for a couple of times, so have it in limits. Eat fruits, fruit salads, and have fruits juices as much as you can which is considered to be extremely great diet.

What is the difference between function and method?

First let's understand function. In C programming language, we use functions which contains a piece of code and every function must have a unique name with which it should be called or invoked.

Example:
#include<stdio.h>
int sum();
void main()
{
  int z;
  z = sum();
  printf("z = %d",z);
}
int sum()
{
 int a=5, b=9, c;
 return c=a+b;
}

In Object-Oriented Programming languages we use objects to invoke methods.
Syntax: Object.Method();

Note: In C langugae we don't have concept of class and object.

Function does not belong to any object or class.
Method belongs to a class.

All methods are functions, but not all functions are methods.