Basics of C Language

1.What do you mean by the C ?

C is a structured,procedural based programming language which is used to develop operating systems and applications.

Linux operating system is written in C language.

C was developed by Dennis Ritchie in 1972 at Bell Laboratories.

It is the mother language of all programming languages. 

2.How will print “Hello world” in C without using semicolon ?

By using  “if statement” or “switch” or “while statement”.
a.Using if statement

void main( )
{
if(printf(“Hello world”))
{
}
}

b.Using switch statement

void main( )
{
switch(printf(“Hello world”))
{
}
}

c.Using While statement

void main()
{
while(!printf(“Hello world"))
{
}
}


3.What are the different storage classes  in C ?

auto,static,register,extern 

4.What do you mean by NULL pointer ?

NULL pointer pointing nothing means It does not point any memory location/address.we can initialise the  pointer as a NULL if we do not know their value at the time of declaration.

5.What do you mean by Static and Dynamic memory allocation ?

Static memory allocation:

When  memory is allocated at compile time then this known as static memory allocation.

Memory size can not be increased  during the execution of the program.

Example int arr[10];

Here arr size is fixed 10.

Dynamic memory allocation

When  memory is allocated at run time or execution of the program then this is known as dynamic memory allocation.

Memory size can be increased during the execution of the program.

Example: int *p=malloc(sizeof(int)*5)

6.What do you mean by stack and heap areas ?

Stack area:

It is used to store local variables and arguments of methods.

Heap area:

It is used to store dynamically created objects using malloc and calloc.

7.What is the difference between the ++x and x++ ?

The ++ operator is known as increment operator.++x means x value will increment by 1 before evaluating the expression.x++ means x value will increment by 1 after evaluating the expression.

Example of prefix incrementation.

Int x=10,y;

y=++x;

Here first x value will increment by 1 after expression will evaluate.

Ie y=11 and also x=11.

Example of postfix incrementation

Int x=10,y;

y=x++;

Here expression first will be evaluated ie y=10.After that x value will increment ie x=11.

8.How can compile C program without a main( ) function ?

#include<stdio.h>

#define start main

Void start( )

{
printf(“hello suman”);

}

9.What do you mean by modulo operator (%)?

Modulo operator is to give remainder when one number is divided by another number.

Example:

a%b=remainder (a>b)

10%3=1

10.what do you mean by l-value and r-value ?

l-value is an expression which is assigned the left side of assignment operator whereas r-value is assigned the right side  of the assigned operator.

Example

Int x=10;

Here x is l-value  & 10 is r-value

11.Write a program to swap two numbers without using third variable.

#include<stdio.h>
Void main(  )
{
Int a=10,b=20;
printf(“before swapping a=%d b=%d”,a,b);
a=a+b; //a=10+20=30
b=a-b; //b=30(new value)-20=10
a=a-b; //a=30-10(new value)=20

printf(“After swapping a=%d b=%d”,a,b);
}

Output:

Before swapping a=10 b=20

After swapping a=20 b=10

12.What do you mean by scope of variable in C ?

Scope of variable means where the declared variable may be accessible inside the program.

13.What do you mean by infinite loop ?

When the loops run infinite times then it is known as an infinite loop.

Example:

void main()
{
for(; ;)
{
//execute code here
}

14.ANSI stands for

ANSI stands for American national standards institute.

15.Write a palindrome number in C programming.

#include<stdio.h>
Void main(  )
{
Int sum=0,number=141,temp,remainder;
temp=number;
while(number>0)
{
remainder=number%10;
sum=sum+remainder;
number=number/10;
}
if(temp==sum)
{
printf(“Number is palindrome”);
}
else
{
printf(“Number is not a palindrome”);
}
}

Output:

Number is palindrome

16.Why use ‘\0’ character in C ?

It is also known as null character which is used at the end of string for the termination.

17. What is the difference between the = &== operator ?

= is an assignment operator which is used to value into the variables and == operator is used to compare the values.

Example:

Int a=10;//This is an assignment operator.

Int b=10

if(a==b) //This is a compare operator.

18.Write the code of the given code

1

12

123

1234

12345

Void main( )
{
Int i,j;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
printf(“%d”,j);
}
printf(“\n”);
}
}

19.What would be the output of the below code ?

void main( )
{
Int a=32767;
printf(“++a=%d”,++a);
printf(“a++=%d”,a++);
}

Output

++a=0

a++=32767

++a=0,Because a will increment value by 1 ie a=32768 which is not the range of integer(- 32767 to 32767).

20.What do you mean by modular programming language ?

Modular programming is a mechanism in which large project/program is broken into small module and solved/executed  individually,Finally all the modules are integrated into a single unit.