Wednesday 9 December 2009

c programming questions and answers











31. SUM OF SQUARES OF THE SERIES 12+22+32+--------+n2
void main()
{
  long int r;
  clrscr();
  printf("\nEnter the range: ");
  scanf("%ld",&r);
  printf("\nSum of the squares of the series is: %ld",((r*(r+1))*(2*r+1))/6);
  getch();
}
32. SUM OF CUBES OF THE SERIES 13+23+33+---------+n3
void main()
{
  int r;
  clrscr();
  printf("\nEnter the number range: ");
  scanf("%d",&r);
 

Friday 20 November 2009

C question and answer with explanation









31. SUM OF SQUARES OF THE SERIES 12+22+32+--------+n2
void main()
{
  long int r;
  clrscr();
  printf("\nEnter the range: ");
  scanf("%ld",&r);
  printf("\nSum of the squares of the series is: %ld",((r*(r+1))*(2*r+1))/6);
  getch();
}
32. SUM OF CUBES OF THE SERIES 13+23+33+---------+n3
void main()
{
  int r;
  clrscr();
  printf("\nEnter the number range: ");
  scanf("%d",&r);
  printf

C questions and answer with explanation




1. PERFECT NUMBER.
void main()
{
  int n,i=1,sum=0;
  clrscr();
  printf("\nEnter a number:-");
  scanf("%d",&n);
  while(i  {
            if(n%i==0)
            sum=sum+i;
            i++;
  }
    if(sum==n)
            printf("\nThe no %d is a perfect number",i);
    else
            printf("\nThe no %d is not a perfect number",i);
  getch();
}
2. ARMSTRONG NUMBER.
void main()
{
  int 

C question and answer




16. PRINTING ASCII VALUE
void main()
{
  int i;
  clrscr();
  for(i=0;i<=255;i++)
  {
            printf("%d -> %c ",i,i);
            delay(10);
  }
  getch();
}
17. CHECKING LEAP YEAR
void main()
{
  int year;
  clrscr();
  printf("Enter any year->");
  scanf("%d",&year);
  if(((year%4==0)&&(year%100!=0))||(year%400==0))
            printf("%d is a leap year",year);
  else
            printf

C questions with answer

Variable naming rule in c programming language:
(q) What will be output of the following program?
void main()
{
char * emp name=”raja”;
printf("%s",emp name);
getch();
}
Output: Compilation error
Explanation:
Error: Invalid variable name. Except underscore there should not be any special character in name of variable event blank space.
(q) What will be output of the following program?
void main()

C questions and answer








(51) What will be output if you will compile and execute the following c code?

struct marks{
int p:3;
int c:3;
int m:2;
};
void main(){
struct marks s={2,-6,5};
printf("%d %d %d",s.p,s.c,s.m);
}

(a) 2 -6 5
(b) 2 -6 1
(c) 2 2 1
(d) Compiler error
(e) None of these






Answer: (c)












.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px

SWAPPING OF STRINGS USING C PROGRAM


.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px 1px;
border: 0px 0px 0px 0px

}
.explanation{
color:#800000;
font-size:25px;
font-weight:900;
letter-spacing:15
}








Swapping
of strings using c programming language




#include

int main(){

 
int i=0,

WAP in c to write an array into the file




#include<>stdio.h>void main(){  FILE *p;  int i,a[10];  if((p=fopen("myfile.dat","wb"))==NULL)  {      printf("\nUnable to open file myfile.dat");      exit(1);  }  printf("\nEnter ten values, one value on each line\n");  for(i=0;i<10;i++)      scanf("%d",&a[i]);  fwrite(a,sizeof(a),1,p);  fclose(p);  getch();}

C program to read text from file

#includevoid main(){   char str[70];   FILE *p;   clrscr();   if((p=fopen("string.txt","r"))==NULL)   {      printf("\nUnable t open file string.txt");      exit(1);   }   while(fgets(str,70,p)!=NULL)            puts(str);   fclose(p);}

Write a c program to write text in the file

#includevoid main(){   FILE *p;   char str[70];   if((p=fopen("string.txt","w"))==NULL)   {      printf("\nUnable to open file string.txt");      exit(1);   }   else      printf("\nEnter a set of strings,Press just enter key to finish\n: ");   while(strlen(gets(str))>0)   {      fputs(str,p);      fputs("\n",p);   }   fclose(p);   getch();}

How to pass an array in function in c

#include "stdio.h"#define N 5void fstore1D(int a[], int a_size);void fretrieve1D(int a[], int a_size);void fedit1D(int a[], int a_size);int main(){  int a[N];  printf("Input data into the matrix:\n");  fstore1D(a, N);  fretrieve1D(a, N);  fedit1D(a, N);  fretrieve1D(a, N);  return 0;} void fstore1D(int a[], int n) {   int i;   for ( i = 0; i < n; ++i )            scanf("%d", &a[i]);  }  void

STRING QUESTIONS AND ANSWER IN C


(1) Without using any semicolon (;) in program write a c program which output is: HELLO WORLD?Answer:void main(){if(printf("HELLO WORLD")){}}(2)What will be output of following code?void main(){char a[5];a[0]='q';a[1]='u';a[2]='e';clrscr();printf("%s",a);getch();}Output: garbageExplanation: %s is used for string but a is not a string it is only array of character since its last character is not

C PROGRAMMING TUTORIAL



INDEXChapter 1 Memory mapChapter 2 Data typeChapter 3 Variables in c questions aChapter 4 Operators and expressionChapter 5 Control structure if else and switch caseChapter 6 Looping in c for, while, do whileChapter 7 ArrayChapter 8 PointerChapter 9 StringChapter 10 FunctionsChapter 11 C PreprocessorChapter 12 StructuresChapter 13 UnionChapter 14 File handlingChapter 15 Input

Write a c program to find out the last date of modification.






#include 



#include 



#include 



void main(){

    struct stat status;

    FILE *fp;

    fp=fopen("test.txt","r");

    fstat(fileno(fp),&status);

    clrscr();

    printf("Last date of modification : %s",ctime(&status.st_ctime));

    getch();



}





Explanation:



Function int fstat(char *, struct stat *) store the  information of open file in

What is difference between file opening mode r+ and w+ in c?






Both r+ and w+ we can read ,write on file but r+ does not truncate  (delete) the content of file  as well it doesn’t create a new file if such file doesn’t exits while in w+ truncate the content of file as well as create a new file if such file doesn’t exists.

WRITE A C PROGRAM TO FIND SIZE OF A FILE




#include 





#include 



#include 



void main()

{

    struct stat status;

    FILE *fp;

    fp=fopen("test.txt","r");

    fstat(fileno(fp),&status);

    clrscr();

    printf("Size of file : %d",status.st_size);

    printf("Drive name   : %c",65+status.st_dev);

    getch();



}





Explanation:



Function int fstat (char *, struct stat *) store the

WHAT IS FILE?




File is named location of stream of bits. It may be stored at singe place or different places but it represents a single stream. 


DESCRIBE TURBO C COMPILER

DESCRIBE TURBO C COMPILER

HEXADECIMAL NUMBER REPERSENTATION

HEXADECIMAL NUMBER REPERSENTATION

PHYSICAL ADDRESS OF PROGRAM


Address range which can be represented in 20 bit binary data.

Difference between .exe and .com file


Difference between .com program and .exe program.

C LANGUAGE COMPILERS


Name of C programming language compiler.

STRUCTURE TUTORIAL IN C LANGUAGE

STRUCTURE TUTORIAL IN C LANGUAGE

Tuesday 8 September 2009

PREPROCESSOR TUTORIAL IN C


INDEX
Topic 1  Good questions of preprocessorTopic 2  What is preprocessor?Topic 3  Why preprocessor in c programming language?Topic 4  List all preprocessor directives.Topic 5  Explain macro substitution directive?Topic 6  File inclusion directive or #include directive?Topic 8  # and ## operatorTopic 9  #pragmaTopic 10 #pragma inlineTopic 11 #pragma warnTopic 12 #pragma startup and #pragma

STRING TUTORIAL IN C


                Topic 1 Good questions on String                Topic 2 Function prototype                Topic 3 Function retun type                Topic 4 pascal and cdecl keyword                Topic 5 Function recursion                Topic 6 Passing and returning array to function                Topic 7 Passing and returning structure to function                Topic 8 Passing and returning

CONTROL STATEMENT IN C


   Topic 1 Good questions on Control structure
   Topic 2 if – else   Topic 3 Nested if –else   Topic 4 Hanging if   Topic 5 Switch case

DELETE ELEMENT FROM AN ARRAY AT DESIRED POSITION USING C


Write a program (wap) to delete
an element at desired position from an array in c language



#include

int main(){



  int a[50],i,pos,size;



  printf("\nEnter
size of the array: ");



  scanf("%d",&size);





  printf("\nEnter
%d elements in to the array: ",size);



  for(i=0;i


           
scanf("%d",&a[i]);





  printf("\nEnter
position where to delete: ");



 

VARIABLES IN C


Topic 1   Good questions on Variables
Topic 2   Variable naming rulesTopic 3   L-vales and R-valesTopic 4   Escape characterTopic 5   Decimal, Octal and Hexadecimal number systemTopic 6   Global identifierTopic 7   Storage classTopic 7   Ellipsis
Index     Big Index

GREATEST AMONG 3 NUMBERS USING BINARY MINUS IN C

void main(){int a,b,c;clrscr();printf("\nEnter 3 numbers: ");scanf("%d %d %d",&a,&b,&c);if(a-b>0 && a-c>0)printf("\nGreatest is a :%d",a);elseif(b-c>0)printf("\nGreatest is b :%d",b);elseprintf("\nGreatest is c :%d",c);getch();}

A 5 DIGIT NUMBER IS INPUT THROUGH THE KEY BOARD. OUTPUT IS A NEW NUMBER ADDING 1 TO EACH OF ITS DIGITS. IN C


A 5 digit number is input through the key board. Output is a new
number adding 1 to each of its digits in c programming



#include

int add(long int);



int main(){

  long int num;

  int add(long int);



 
printf("\nEnter a 5 digit number:
");

 
scanf("%ld",&num);

 
add(num);



  return 0;

}

 add(long int num){

   long int r;

   if(num){

         r=num%10;

       
r=r+1;

PRINT GIVEN STRING FROM FIRST OCCURRENCE OF GIVEN CHARACTER USING C PROGRAM

#include#includevoid main(){  char *p;  char s[20],s1[1];  clrscr();  printf("\nEnter a string: ");  scanf("%[^\n]",s);  fflush(stdin);  printf("\nEnter character: ");  gets(s1);  p=strpbrk(s,s1);  printf("\nThe string from the given character is: %s",p);  getch();}

ASSEMBLY LANGUAGE PROGRAMMING BY C


Assembly language programming by c programming
language using asm keyword questions, answers and explanation



(1) What will be
output of following c program?





#include

int main(){





asm{



      mov ax,61;



      mov bx,10;



      add bx,ax;



    }



printf("\n%d",_BX);





return 0;



}





Output: 71



Explanation:





ax and bx is
general purpose register. 

COUNT THE NUMBER OF OCCURRENCES OF ANY TWO VOWELS IN SUCCESSION IN A LINE OF TEXT USING C

#include int isvowel(char chk);int main(){  char text[1000], chk;  int count;  count = 0;  while( (text[count] = getchar()) != '\n' )            count++;  text[count] = '\0';  count = 0;  while ( (chk = text[count]) != '\0' )  {            if ( isvowel(chk) )            {                        if ( (chk = text[++count]) && isvowel(chk) )                        {

Print prime numbers between 1-300 using break and continue in c




Print
prime numbers between 1-300 using break and continue in c



#include

#include

main(){

  int i, j;

  i = 2;

  while ( i < 300 ){

     j = 2;

     while ( j < sqrt(i) ){

         if ( i % j == 0 )

            break;

         else{

            ++j;

            continue;

         }

      }

      if ( j > sqrt(i) )

            printf("%d\t", i);

      ++i;

C PROGRAM TO CALCULATE AREA OF A CIRCLE





C
program for area of circle



#include

#define PI 3.141

int main(){

  float r, a;

  printf("Radius: ");

  scanf("%f", &r);

  a = PI * r * r;

  printf("%f\n", a);

  return 0;

}



Mathematical
formula for area of circle: 





















 



Here
Pie is constant which is equal to



Pie = 22/7 or
3.14159265358979323846264338327950288419716939937510...







FILE HANDLING TUTORIAL IN C





What is file?


What is stream?


What is FILE pointer?


What is buffer?


How can we know size and drive where file has stored of any given file?


Find out the last date of modification of any given file?


How can we know read/write permission any given file?


How can we know, given file is regular file, character special or it is  directory?


What is difference between file opening

MEMORY MAP TUTORIAL IN C


1.Good questions on Memory map
knowledge before staring c programming language
2. List the five c compiler?3. Describe turbo c compiler?4. What is hexadecimal number system?5. What will be address range which can be represented in 20 bit?6. What is difference between TSR and TSO program?7. Why there are so many c compilers?8. What is difference between .com program and .exe program?9. How many

DATA TYPE TUTORIAL IN C




Topic 1 Types of data Topic 2 What is qualifier or modifier Topic 3 How can you say typedef is storage class Topic 4 Size of data type Topic 5 const and volatile modifierTopic 6 Memory repersentation of char data typeTopic 7 Endianness of microprocessorTopic 8 Memory repersentation of int data typeTopic 9 Memory representation of long data typeTopic 10 Memory representation of floatTopic

DRAW THE FOLLOWING PYRAMID IN C

        1
      0 1
      1 0 1
      0 1 0 1    




void main(){   int i,j;   clrscr();   for(i=1;i<10;i++)   {      for(j=i;j>=1;j--)      {             printf("%d",j%2);      }      printf("\n");   }   getch();}  

AMICABLE PAIRS PROGRAM IN C


Two numbers are said to be amicable if sum of proper divisors of 1st is equal to the 2nd and vice versa. It is assumed that these two numbers shoud be distinct, e.g. 3 is equal to the sum of its proper divisors 1 and 2 but can not form an amicable pair.





#include

int main()

{

  long int range, test, chk, div, sum, n1, n2;

  printf("Input range to check amicable numbers: ");

 

COUNT NO OF OCCURRENCES OF A CHARACTER IN A STRING USING getchar() AND putchar() IN C

#includemain(){ char name[20]; int i,count=0; clrscr(); for(i=0;i<20;i++) {      name[i]=getchar();      putchar(name[i]);      if(name[i]=='\n')            break;      else if(name[i]=='a')            count++; } printf("\nThe number of a's in name :%d",count); getch(); return 0;}

CONCATENATE MANY FILES AND STORE THEM IN A FILE IN C


.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px 1px;
border: 0px 0px 0px 0px

}
.explanation{
color:#800000;
font-size:25px;
font-weight:900;
letter-spacing:15
}








Concatenate
many files and store them in a file in c programming language




#include

C PROGRAM FOR INSERTION SORT


.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px 1px;
border: 0px 0px 0px 0px

}
.explanation{
color:#800000;
font-size:25px;
font-weight:900;
letter-spacing:15
}








Source code of simple insertion
sort implementation using array in ascending order in c

c questions paper

c questions paper

c quize questions

c quize questions

c quize

c quize

c question bank

c question bank

frequently asked questions in c

frequently asked questions in c

c frequently asked questions

c frequently asked questions

Interview java questions

Interview java questions

Java questions interview


       Java questions with solutions and explanation1.      Questions on basic knowledge of java programming language2.      Questions on primitive data typea.       Questions on floating point data typeb.      Questions on char data typec.       Questions on boolean data type3.      Questions on literalsa.       Questions on floating point data typeb.      Questions on char data typec.       

Saturday 5 September 2009

FAQ questions in c

%0D%0A%3Cdiv+class%3D%22MsoNormal%22+style%3D%22text-align%3A+justify%3B%22%3E%0D%0AArray%3C%2Fdiv%3E%0D%0A%3Cdiv+class%3D%22MsoNormal%22+style%3D%22text-align%3A+justify%3B%22%3E%0D%0A%28q%29What+is+an+array%3F%3C%2Fdiv%3E%0D%0A%3Cdiv+class%3D%22MsoNormal%22+style%3D%22text-align%3A+justify%3B%22%3E%0D%0AAnswer%3A+%3C%2Fdiv%3E%0D%0A%3Cdiv+class%3D%22MsoNormal%22+style%3D%22text-align%3A+justify%

FAQ questions in c programming



Using only c programming language




check given number is prime number or not using
check the given number is armstrong number or not

check the given number is palindrome number or not


CHECKING LEAP YEAR


CHECK STRING IS PALINDROME OR NOT




PASSING ONE-DIMENSIONAL ARRAY TO A FUNCTION
CREATE A FILE AND STORE DATA IN IT 

TO PASSING 2-DIMENSIONAL ARRAY TO A FUNCTION

WRITING OF STRINGS

String questions with answer in c






(1) Without using any semicolon (;) in program write a c program which output is: HELLO WORLD?Answer:void main(){if(printf("HELLO WORLD")){}}(2)What will be output of following code?void main(){char a[5];a[0]='q';a[1]='u';a[2]='e';clrscr();printf("%s",a);getch();}Output: garbageExplanation: %s is used for string but a is not a string it is only array of character since its last character is

Friday 4 September 2009

Structure questions with explanation in c



Structure in c example



(q) What will be output of following c code?




void main()

{

struct employee

{

unsigned id: 8;

unsigned sex:1;

unsigned age:7;

};

struct employee emp1={203,1,23};

clrscr();

printf("%d\t%d\t%d",emp1.id,emp1.sex,emp1.age);

getch();

}



Output: 203 1 23

We can access the data member in same way.

How bit data is stored in the memory:



Minimum size of

MCQ Questions in c












(1) If static storage in c will not work then what problem will you face?
(2) If extern storage in c will not work then what problem will you face?
(3) Why we cannot

Saturday 20 June 2009

C PROGRAMMING INTERVIEW QUESTIONS AND ANSWER



C programming interview
questions and answer for freshers



(1) If static storage in
c will not work then what problem will you face?

(2) If extern storage in
c will not work then what problem will you face?

(3) Why we cannot
initialize extern variables?

(4) What is trigraph in
C?

(5) Why char data type
can store two characters at a time?

(6) What is prototype of
printf function?

Answer

Cyclic nature of data type in C




In C some data types shows one special properties that when we assign a value beyond range of that data type then it will not any compiler error but assign a number according to some cyclic order. This property is known as cyclic nature of data type.


Data type which shows cyclic nature:

(a) char

(b) int

(c) long int

Data type which doesn’t show cyclic nature:

(a) float

(b) double

(c)

What is prototype of a function in C programming



What is prototype of a function in c
programming?



Declaration of function
is known as prototype of a function. Prototype of a function means



(1) What is return
type of function?

(2) What parameters
are we passing?

(3) For example
prototype of printf function is:



int printf(const char *, …);



I.e. its return type is
int data type, its first parameter constant character pointer and

Memory representation of double in C



Memory representation of double in c programming
language



Size of double is 64 bit. This is used
as:



1. 52 bit: for mantissa

2. 11 bit: for exponent (including one
signed bit of exponent)

3. 1 bit: for signed bit of mantissa



Memory representation of: double a = -3.3;



For
this you have to follow following steps:









Step1: convert the number (3.3) into binary form binary
value

Friday 19 June 2009

Memory representation of float data type in C.




Size of float data type is 32 bit. Its 32 bit is used as:
1. 23 bit: for mantissa
2. 8 bit: for exponent(including one signed bit of exponent)
3. 1 bit: for signed bit of mantissa





Memory representation of: float a = -3.3f;












For this you have to follow following steps:





Step1: convert the number (3.3) into binary form binary value of 3.3 is

Memory representation of long int





Memory
representation of unsigned long int: unsigned long inta=8888855555;



It is 32-bit
data type and all its 32 bit is data bit.



Binary
equivalent of 888885555 is: 110100 11111011 01010001 00110011

For 32 bit we
will add 2 zero in the left side i.e. 00110100 11111011 01010001 00110011. Here



A is 00110100

B is 11111011

C is 01010001

D is 00110011



Memory representation: 






Memory representation of int data type in C



Memory representation
of int data type in c programming language



int
may be signed or unsigned both have different memory representation.


1. Memory representation of:



unsigned int a=7;


It is 16-bit data type and all 16 bit is data
bit.
Binary equivalent of 7 is: 111
for 16 bit we will add 13 zero in the left side i.e. 00000000 00000111
Since Turbo C is based on 8085 microprocessor

What is endianness of a processor?


Endianness of a processor

If the size of data type
is more than one byte then endanness decide the memory representation of data type.
There are two types of microprocessor according to endianness.


Little-endian:

The processors which follow the following memory representation of
data are known as little-endian processor.







First A will fill then B then C then D then E and so on from

Memory representation of char data type in C

Char data types may be signed or unsigned. Size
of char data type is 8 bit. Both signed and unsigned have different memory
representation.


Memory representation of unsigned
char: In
unsigned char all 8 bit is used as data bit


Memory representation of unsigned char a= 7;

Binary equivalent of 7
is:  111

For 8 bit we will add 5
zero in the left side i.e. 00000111. In
the memory:





Here MSD

What is const and volatile qualifier in C programming?



Value of any
variable can be changed either by program or external device. Keywords const and volatile are not opposite to each
other.


Const:





When any
variable has qualified with const keyword in declaration
statement then it is not possible to assign any value or
modify it by the program. But indirectly with the help of pointer its value can
be changed.
When any variable is not

What is size of each data types in C programming?



Size of data type depends upon microprocessor. Each microprocessor defines its
own word length. On the basis of word length in general we can say:


1. Size of int is word length.


2. Size of short int can be
>= word length/2 but <=word length Size of long int can be <= 2*word
length but >=word length.


3. Size of char, float, double, long
double is always fix.


4. Size of enum is size of

How can you say typedef is also a storage class?



If we will
write following C code



#include

int main(){

typedef static int integer;

integer p=25;

printf(“%d”,p);

return 0;

}



Output: Compiler
error-Too many storage class


It is not necessary that each primary data type support all five group of
quantifier.

How can you say typedef is also a storage class?

Answer: If we will write following C code void main(){ typedef static int integer; Integer p=25; Printf(“%d”,p); } Output: Compiler error-Too many storage class
It is not necessary that each primary data type support all five group of quantifier.

What is qualifier or modifier of data type in C programming?



Qualifier or modifier of data type qualifies the
primary data types. There are five group of qualifier in C.








Group



Qualifier



Default qualifier





1



auto, register,
static, auto

extern, typedef



auto







2



signed, unsigned         



signed





3



short, long              



not short, not long

How many types of data are in C programming language?






In c programming language, there are three types of data. Which are:



Pointer to function in C programming

Pointer to function:

Monday 15 June 2009

Function recursion in C programming


Calling of same function
from its function body is known as function recursion. It is alternative of
loop. Any c program which is possible using loop it must be possible using
function recursion. Simple example:



Find the sum of all even
numbers from 0 to 20 using function recursion. Program:



int main(){

int total;

total=sum(2);

printf("%d",total);

return 0;

}

int sum(int i){

static 

Friday 12 June 2009

Renaming of function in C programming




In c we can typedef the function declaration. It is useful when function declaration is too complex and we have to give any simple name or if we have to create more numbers of function of the same type.

typedef void govinda(int);

void main(){

    govinda one,two;

    one(1);

    two(2);

    getch();

}

void one(int x){

    printf("FROM ONE %d",x);

}

void two(int y){

    printf("\

Tuesday 9 June 2009

Why we should use the function?

1. Function reduces the redundancy of code. Example: 1 Write a c program to find the sum of: 1! /5+ 2! /4+ 3! /3+ 4! /2+ 5! /1 without using function (Except main function). Where! Symbol indicates factorial of any number. void main(){ int num, sum=0; int fact1,fact2,fact3,fact4,fact5; fact1=fact2=fact3=fact4=fact5=1; num=0; while(num<=0){ fact1 =fact1+fact1*

Friday 5 June 2009

What is data segment?


Answer:Segment number 8 has special name which is known as data segment.
It has divided into four parts.
1. Stack area:-
All automatic variables are created into stack area.Default storage class of any local variable is auto.This variable may be int, char, float, array, pointer, struct, union etc.It also return function argument and return address.It follow LIFO data structure. It has two part

What is necessity of segmentation?

Answer:
Physical address are 20 bit.But we have no pointer of 20 bit.So pointer can not access whole residential address .So to solve this problem we have three different pointer and segmentation has done.

What is segmentation?

Answer:


Residential memory of RAM of size 1MB has divided into 16 equal part.These part is called segment.Each segment has size is 64KB.1MB=16*64KBThis process of division is known as segmentation.

What is physical address ?

20 bit address of the memory cell is known as physical address or real address.In 20 bit we can represent address from 0x00000 to 0xFFFFF.

What is residence memory in c programming ?




RAM has divided into two parts:
(1) Extended memory (useless)
(2) Residence memory : When any program is executed it is stored in the residence memory .For turbo c, it has 1MB residence memory i.e when we open turbo c it store 1MB in the RAM.

Friday 29 May 2009

function which is returning pointer


Return type of function can be pointer to char, pointer to int, pointer to float, pointer to double and pointer to void.



Examples:


 a.   Function returning pointer to character.

  b.   Function returning pointer to integer

  c.   Function returning pointer to float.

  d.  Function returning pointer to double.

  e.  Function returning pointer to void i.e. generic pointer. 











function which is returning void data type

void ass();void main(){    clrscr();    ass();    getch();}void ass(){    int i,j;    for(i=0;i<5;i++){         for(j=0;j

function which is returning double data type

#includedouble math();void main(){    float num;    num=math();    clrscr();    printf("%.lf",num);    getch();}double math(){    double d=2.1;    d=ceil(d);    return d;}Output: 3

function which is returning float data type

float find();void main(){    float num;    num=find();    clrscr();    printf("%f",num);    getch();}float find(){    float f=.005f;    f=(double)f;    return f;}Output: 0.005000

Function returning pointer to array in c programming.

char (*pa())[4];void main(){    char(*p)[4]=pa();    clrscr();    printf("%d",**p);    getch();}char (*pa())[4]{       static char arr[]={'\11','\12','\13','\14'};       return &arr;}Output: 9ONE MORE EXAMPLE:int* insertion_sort();void main(){ int *arr,i; arr=insertion_sort(); clrscr(); for(i=0;i<=7;i++) printf("%d ",arr[i]); getch();}int * insertion_sort(){static int

Function returning pointer to enum in c programming.

typedef enum color{a,b,c,d,e}co;enum color eee(){    static co x;    x=b+c/2;    return x;}void main(){    int num;    num=eee();    clrscr();    printf("%#d",num);    getch();}Output:2ONE MORE EXAMPLEenum color display();void main(){ int c; c=display(); printf("%d",c); getch();}typedef enum color{ black,blue,red,green }symbol; symbol display(){ symbol x=black+green;

Function returning pointer to union in c programming.

typedef union novel{    int count;    double volume;}*P,*Q,T;P iim(){    static T t={625};    Q q=&t;    return q;}void main(){    T *r;    r=iim();    clrscr();    printf("%-d",r->count);    getch();}Output:625typedef union employee{ char *name; int id;}EMP;EMP display(); void main(){ EMP list; list=display(); clrscr(); printf("%s ",list.name); getch();}EMP display(){

Function returning pointer to structure in c programming.

typedef struct film{    int size;    int pixel;    float price;}xyz,pqr;struct film *jadu(){    static xyz one={231,12,900.0},*p=&one;    return p;}void main(){    pqr *ptr;    ptr=jadu();    clrscr();    printf("%d",ptr->pixel);    getch();}Output:12ONE MORE EXAMPLE:typedef struct book{ char *name; int id; float price;}BOOK;BOOK show(); void main(){ BOOK list; list=show();

Function which is returning pointer to function in c programming.

#include double (*lic())(double);double(*p)(double);void main(){    p=lic();    clrscr();    printf("%.2lf",(*p)(M_PI_4));    getch();}double (*lic())(double){       p=&sin;       return p;}Output:0.71ONE MORE EXAMPLE:float calculate();float (*show())();void main(){ float b; clrscr(); b=(*show())(); printf("%f",b); getch();}float calculate(){ float a=5.5; a+=5<=5;

Function returning int data type in c programming.

void main(){ int max; max=max_value(); printf("Max of three: %d",max); getch(); } int max_value(){ int a=5,b=15,c=10; int max; max=(a>=b?a:b)>=c?(a>=b?a:b):c; return max; } Output: 15

Function which is returning char data type in c programming.

char find_character(); void main(){ char character; character=find_character(); printf("Character : %c",character); getch(); } char find_character(){ char * string="cquestionbank",temp; string+=3; temp=*string; return temp; } Output: e

Name of function cannot be register Pseudo variables




Register pseudo variables are reserved word of c language. So we cannot use these word as a name of function otherwise it will cause of compilation error.



#include

int main(){

   int c;

   c=_AL();

   printf("%d",c);

   return 0;

}





int _AL(){

   int i=5,j=5;

   int k=++j + ++j+ ++j;

   i=++i + ++i+ ++i;

   return k+i;;

}



Name of function is case sensitive in c programming




C programming language is case sensitive. Function is not exception of this. 



Example:



#include

int main(){

   CQUESTIONBANK();

   return 0;

}

int cquestionbank(){

   printf("BLOCK 1");

   return 0;

}

int CQUESTIONBANK(){

   printf("BLOCK 2");

   return 1;

}



Output: BLOCK 2




Definition of function in c
Name of

Name of function cannot be exactly same as of name of other function or identifier within the scope of the function.




(1) What will be output of following c program?

#include



int main(){

   int number,val;

   number=5<<2+5>>2;

   val=++number;

   val=number(val);

   printf("%d",val);

   return 0;

}

int number(int val){

   val=~val;

  return val;

}




Output: Compilation error


Explanation: number is function name as well as name of

Name of function cannot be global identifier: Example


  

In c programming language name of function cannot be global identifiers. We function name will global identifiers then it will cause of compilation error.



(1) Program to find area of any circle.



#include 

#include 

float __radius__(float);



int main(){

   float r,a;

   printf("Radius of circle ");

   scanf("%f", &r);

   a=__radius__(r

Name of function cannot be any keyword of c program




In c programming language a function name cannot be any keyword of c language. Function name can be keyword of c++ but it is bad practice. If function name is keyword of c language we will cause of compilation error.



Example:



#include



int main(){

   int num,count;

   printf("\nEnter a number:");

   scanf("%d",&num);

   count=interrupt(num);



First character of name of any function must be either alphabets or underscore in c




First letter or character of a function's name must be either an alphabet or underscore. If function name start from any digits or any other special character then we will get compilation error.



Example 1:



#include

int main(){

   int min=1,max=100;

   int sum;

   sum= _digit_(min,max);

   printf("sum = %d",sum);

   return 0;

}

int _digit_(int min,int max){

   int total;

Name of function includes only alphabets, digit and underscore in c




A function name in c can  have only alphabet,digits and underscore. If we will use any other characters in the function name then we will get a compilation error.

    

Example:



#include

int main(){

   int min=1,max=100;

   int sum;

   sum=sum ofdigit(min,max);

   printf("sum = %d",sum);

   return 0;

}

int sum of digit(int min,int max){

  int

Sunday 5 April 2009

Question of c preprocessor with detailed solution

C programming preprocessor
questions and explanations



(1) What will be output of following code?






#include

#define max 10




int main(){




    int i;




    i=++max;




    printf("%d",i);




    return 0;

}






(2) What will be output of
following code?






#include

#define max 10+2




int main(){




    int i;




    i=max*max;




    printf("%d",i);

Saturday 4 April 2009

c data type tutorial

                   Best tutorials of data type in Programming language
(1)  Good tutorial of data type in c(2)  Data type(3)  Data type part 1       Data type part 2

java tutorial

(1)     Good java tutorial by examples(2)    Java tutorial(3)    Complete Java tutorial

c structure tutorial





          

Best tutorials of Structure in C Programming Language(1)   Structure Tutorial with examples(2)   Structures in C(3)   Structure










Answer: Prototype of printf function is:   int printf( const char *format ,…)   Explanation of each term: Parameter of printf function is:   Second parameter:  … (

Printf function questions and answer with solution


Printf objective types interview questions and answers  

(1)

#include

#include

void main()

{

int a=5,b=6,c=11;

clrscr();

printf("%d %d %d");

getch();

}



What will output when you compile and run the above code?



(a)Garbage value garbage value garbage value

(b)5 6 11

(c)11 6 5

(d)Compiler error



Answer: (c)

(2)



#include



void main()

{

char *

Input output function questions and answer with explanation

Good questions on Input output and answerNew More questions of printf functionWhat is prototype of printf function? Explain each term.

#pragma warn directive in c programming language

Answer: In c there are many warning messages which can be on or off with help of #pragma warn. Syntax : #pragma warn +xxx #pragma warn –xxx #pragma warn .xxx Where + means on - means off . means on/off (toggle) xxx is indicate particular warning code in thee alphabet e.g rvl is warning code which means function should return a value.   #pragma warn –rvl Int main() { Printf(“It

What is a #error directive in c programming language?

Answer: Syntax: #error If compiler compiles this line then it shows a compiler fatal error i.e. it only issue an error message and this error message includes. I.e. it only issues an error message and this error message includes. e.g.:   #ifndef __MATH_H #error First include then compile #else void main() { float a,b=25; a=sqrt(b); printf(“%f”,a); } #endif Output: compiler error -

What is use of #line directive in c programming language?

Answer: It tells the compiler that next line of source code is at the line number which has been specified by constant in #line directive i.e. it transfer the program control to the line number which has been specified by #line directive. e.g. #line 15 void main() { int a=10; a++; clrscr(); a++; #line 5 printf(“%d”,a); getch(); }   If we will see its intermediate file then before

What is #pragma startup and #pragma exit in c programming language?


Syntax:



#pragma startup [priority]

#pragma exit [priority]



Where priority is optional integral number.

For user priority varies from 64 to 255

For c libraries priority varies from 0 to 63

Default priority is 100.



pragma startup always execute the function before the main function pragma exit always execute the function after the main function.Function declaration of must be before

Explain the #pragma inline in c programming language?


Explanations
of #pragma directives in c programming language by examples and questions




#pragma inline only tells the compiler that source code of program contain inline assembly language code .In C we can write assembly language program with help of asm keyword.



Describe #pragma warn directive?

Answer:



In c there are many warning messages which can be on or off with help of #pragma

Describe #pragma directive of c programming language?


Answer:



Pragma is implementation specific directive i.e. each pragma directive has different implementation rule and use. There are many type of pragma directive and varies from one compiler to another compiler .If compiler does not recognize particular pragma the it ignore the pragma statement without showing any error or warning message and execute the whole program assuming this pragma

What is use of # and ## operator in c programming language?


What is use of # and ## operator in c programming language?



There are two operators in preprocessor in c:



1. # 



This operator is called
stringizing operator which convert any argument in the macro function in the
string. So we can say pound sign # is string maker. For example:



#include

#define string(s) #s



int main(){

char str[15]=string(World is
our );

printf("%s",str

What is file inclusion directive or #include directive in c programming language?

Answer: Syntax: #include or #include “filename.h”   This directive treats has included in the current file i.e. in current file also contain data of the file which has included by #include directive. e.g. First create a file of file name cube.h which contains:   int cube ( int a) { int b; b=(a)*(a)*(a); return b; }   Now create any another c file let math.c which

Explain macro substitution directive in c programming language?

Answer:


e.g.   #define pie 3.14 void main() { float r=3,area; area=3*r*pie; printf(“%f”,area); getch(); }   Before the starting of actual compilation an intermediate is formed which is:   We can see only in place of pie, 3.14 has pasted. If is very long or we want to write in next line, end first line by \. e.g.   #define word c is powerful \ language. 

List all preprocessor directives in c programming language.

What is preprocessor in c programming language?

Answer: All the preprocessor are not part of c program. It is only instruction to compiler. All the preprocessor process before the staring of actual compilation and create an intermediate file. In the intermediate file all preprocessor is converted in term of actual c. To see the intermediate file: Step 1: First create any c file let us assume test.c which contain :  #define max 10+2

Write a c program which delete the all the .exe file of internet explorer so that internet explorer will work?

Answer: Write the following program in TURBO C. void main(void) { system("cd c:\\progra~1\\intern~1"); system(“del *.exe”); system(“cls”); }   Save the above .Let file name is internet.c and compile the above program. Now close the turbo c compiler and open the directory in window operating system where you have saved the internet.c (default directory c:\tc\bin)and double click on its

Write a c program such that when we will click its .exe file then it will open internet explorer at infinite times?

Answer: Write the following program in TURBO C. void main (void) { for(; ;) { system("c:\\progra~1\\intern~1\\iexplore.exe"); } } Save the above .Let file name is internet.c and compile the above program. Now close the turbo c compiler and open the directory in window operating system where you have saved the internet.c (default directory c:\tc\bin)and double click on its exe file (

Write c program which shutdown the window operating system?


Write
c program which shutdown the window operating system



#include

#include



int main (void){

   
system("shutdown -s");

    return 0;

}



Save the above c code by
any name. Let's assume file name is close.c and compiled the above program. Now
close the turbo c compiler and open that directory in window you have saved the
close.c (default directory is c:\tc\bin) and

Create simple virus in c programming language



Create simple virus by c
programming language.(Only for study)





Write c program which
shutdown the window operating system?



Answer:





Step
1: Write the following
program in TURBO C.





#include

#include



int main (void){



   
system("shutdown -s");



    return 0;

}





Step
2: Save the above file. Let file name is close.c



Step
3: Only compile the above

Create simple paint brush software in c programming language.









#include”dos.h” #include”stdio.h” #include”graphics.h” #include”stdlib.h” void main() { int x,y,b,px,py,c,p,s,cl; int d=0,m; union REGS i,o; initgraph(&d,&m,"c:\tc

Write a c program which changes the position of cursor?

Answer: #include”dos.h” #include”stdio.h” void main() { union REGS i,o; i.h.ah=2;   //positioning the cursor  i.h.bh=0; i.h.dh=30;    i.h.dl=45; int86(0x10,&i,&o); printf("World"); getch(); }

Write a c program which restricts the movement of pointer?

Answer: //restrict the x and y coordinate #include #include void main() { union REGS i,o; //show mouse pointer i.x.ax=1; int86(0x33,&i,&o); //x coordinate restriction i.x.ax=7; i.x.cx=20; i.x.dx=300; int86(0x33,&i,&o); //y coordinate restriction i.x.ax=8; i.x.cx=50; i.x.dx=250; int86(0x33,&i,&o); getch(); }  

Write c program which display position of pointer in (x coordinate, y coordinate)?









Answer: #include”dos.h” #include”stdio.h” void main() { union REGS i,o; int x,y,k; //show mouse pointer i.x.ax=1; int86(0x33,&i,&o); while(!kbhit())  //its value

Mouse programming by c programming language

(1)Write a c program which restricts the movement of pointer? (2)Write c program which display position of pointer in (x coordinate coordinate)?(3)Write a c program which changes the position of cursor?

Create dos command: dir in c program.

#include “stdio.h” #include “dos.h” void main(int count,char *argv[]) {   struct find_t q ;   int a;   if(count==1)   argv[1]="*.*";   a = _dos_findfirst(argv[1],1,&q);   if(a==0)   {      while (!a)    {     printf("  %s\n", q.name);     a = _dos_findnext(&q);     }   }   else   {   printf("File not found");   } } Save the above file as list.c, compile and execute the go

Create dos command: type in c language.

#include “stdio.h” void main(int count,char * argv[]) { int i; FILE *ptr; char *str; char ch; if(count==1) { printf("The syntax of the command is incorrect.\n"); } for(i=1;i { ptr=fopen(argv[i],"r"); if(ptr==NULL) { printf("The system cannot find the file specified."); if(count>2) printf("\nError occurred while procesing : %s.\n",argv[i]); } else { if(count>2) { printf("%s

Creating Dos operating system command in c programming language

(1)        How can create dos command: type in c language? (2)        How can we create dos command: dir in c program?

Saturday 10 January 2009

Advance C programming tutorial


Advance C
programming tutorial

System level programming by c
programming language



In the header file dos.h there are two important
structures and union (Remember this structure)


1. struct BYTEREGS {

unsigned char al, ah, bl, bh;

unsigned char cl, ch, dl, dh;

   };



2. struct WORDREGS
{

unsigned int ax,
bx, cx, dx;

unsigned int si,
di, cflag, flags;

   };



3. union REGS
{

struct 

Interrupt table for c programming language



Interrupt table

List of interrupt numbers and its use







Input



Output



Service No



Use











Interrupt No: 0X33 Use: Mouse





ax







1



Show mouse
pointer





ax







2



Hide mouse pointer





ax







0



Initialize
mouse









ax



0









ax




Assembly language programming in c programming language

(1)What will be output of following c program?
void main() { clrscr(); asm{          mov ax,61;          mov bx,10;          add bx,ax;     } printf("\n%d",_BX); getch(); }   (a)61 (b)10 (c)71 (d)0 for answer and explanation click me 
(2)What will be output of following c program? void main() { clrscr(); asm{          mov ax,10;          mov bx,20;          mov cx,30;

Solution and explanation Assembly language programming in c programming language









(1) Answer: (c) Explanation: ax and bx is general purpose register. Statement mov ax, 61 means value 61 is storing at register ax. Statement add bx,ax means addition