C - Basics

1. Command-line:
  • It describes what's going on inside a program, so that person looking at the source code does not have a hard time figuring it out.
Types of comments:
(i)Single line comments:
Syntax:
        /*Statements*/
Example:
        /* This is the addition program*/
 (ii)Multiline comments:
  Syntax:
       //Statement
2.Variables:
  • A variable is nothing but it allocates the memory space and holds the values.
Syntax:
Data_type variable_name;
Example:
int x, y;
Rules for naming the variables:
  • The first character must be an alphabet or an underscore(_).
  • No commas or blank spaces are allowed within a variable name.
  • No special symbols, an underscore can be used in a variable name.
User defined variables:
a). Type declaration:
  • It is used to allow the user to define an identifier that would represent an existing data type.
Syntax:
typedef data_type identifier;
Example:
typedef int marks;
marks m1,m2,m3;
b). Enumerated data type:
  • It is used to create user-defined data types i.e. the programmer can create their own data type and define what values the variables of those data types can hold.
Syntax:
enum  enum _name{value 1,value 2, ......,value n};
Example:
enum day{mon,tue,wed,...sun};
Scope of variables:
  • It implies the availability of variables within the program.
  • It is divided into two types.
1). Local variable:
  • The variables which are defined inside the function block called a local variable.
Example:
void main()
{
int a,b;//local variable
......
}
2). Global variable:
  • The variables that are declared before the main() function is called a global variable.
Example:
int a,b;//Global variable
void main()
{
......

}
3.Data types: 
  • It means kinds of data that means numbers or words.
  • The most widely used data types are
1. int (integer) - real numbers
Ex: 1, 2, -5, 1311
2. float - decimal number:
Ex: 1.45, 0.001
3. char(character)- Alphabets
Ex: k,f,v,h
4.double – combinations of int and float numbers
Ex: 1.001,89,1654
4. Input function: 
  • This function is used to value get from users.
Syntax:
scanf(“ format specifiers ”,variable_name);
Example:
scanf("%d",z);
5.Format specifiers:
  •  It is used to indicate unknown value for types to display on the output screen and also get value from user. ( i.e. Holds unknown values)
There are,
6.Output function: 
  • This function is used to show details for users.
Syntax:
printf(“Statements”);
Example:
printf("Welcome to whereisstuff");
7.Escape sequence: 
  • This is used for aligning output on the screen.

Escape sequence
Description
Example
Output
\n
Newline or next line
printf(“Hai! \n I am Sabrina.”)
Hai! I am Sabrina.
\t
Horizontal tab(one tab space)
printf(“Hai\t Hello”)
Hai                   hello
\’
Display single-quotes
printf(“I don\”t know”)
I don’t know
\”
Display double-quotes
printf(“/“Hey/”’)
“Hey”
\\
Print slash
printf(“a//b”)
a/b


















Example program:

/* To print "Welcome to whereisstuff " and multiply two numbers  */
#include<stdio.h>
#include<conio.h>//header files
void main()//main function
{
int x,y,z;//variable-declaration
clrscr();
printf("Welcome to whereisstuff\t\n Multiply two numbers\n");//print fun
printf("Enter x and y value:\n");
scanf("%d%d",&x,&y);//get value from user and store
z=x*y;
printf("Multiply value is: %d",z);//result disply
getch();
}

Output: 

Share:

No comments:

Post a Comment

Recent Posts

Service Support

Need our help to Learn or Post New Concepts Contact me