Friday 30 January 2009

c coding



c objective questions and answer
c language questions
c language





c language questions

(5)Find the correct output void main() { char a[4]=”rama”; char b[]=”shyama”; printf(“%d %d”, sizeof(a),sizeof( b)) ; } (a) 4 7 (b) 5 6 (c) 5 7 (d) 4 6 (6)Find the correct output void main() { int a[]={‘a’,’b’,’c’}; printf(“%d”, sizeof(a)); } (a)3 (b)4 (c)can’t be initialized (d)None of these (7)

c language

(10)Identify the true statement   (a)Memory allocated by an array can be deallocated using free() function   (b)C also supports zero length array (c)Array can be used to hold dissimilar kinds of data  (d)Working beyond array size is risky     (11)Which is true about array?  (a)Array can be dynamic   (b)Using malloc memory can be allocated for array during run time   (c)

Sunday 25 January 2009

Sql questions and answer with solution

commonly asked question in sql with solution for p...

good questions of sql with solutions

questions on natural,inner & outer joins in sql wi...

BE MASTER IN SQL IN THREE HOUR

DATA DEFINATION LANGUAGE IN SQL

NAMING CONVENTIONS IN SQL

CONSTRAINTS IN SQL

DATA TYPES IN SQL

DEFINING A CONSTRAINT IN SQL

FOREIGN KEY CONSTARINT IN SQL

NOT NULL CONSTRAINT IN SQL

UNIQUE KEY Constraint IN SQL

Friday 23 January 2009

C coding questions

(1)What will be output when you compile and execute the following code? void main() {     int i,j;     clrscr();     for(i=0;i<5;i++)     {        for(j=0;j<5;j++)        {            printf("*");          }        printf("\n");     }     getch(); }For output click me (2)What will be output when you compile and execute the following code?   void main() {     int i,j;    

C coding questions and answer

(1)   ***** ***** *****   (2)   * ** *** **** ***** ****** *******   (3)   ** **** ****** ******** ********** ************   (4)   * *** ***** ******* *********   (5)   * **** ******* **********   (6)   ****** ***** **** *** ** *   (7)   ******** ****** **** ** *   (8)   ********* ******* ***** *** *   (9)   ** **** ******** **

Wednesday 14 January 2009

c coding questions and answer


Best questions of preprocessor with answer



(1)

#include

#define division 10\3

int main(){

    printf("%d",division); 

    return 0;   

}



What will be output if you compile and execute the above code?

(a)3

(b)4

(c)103

(d)Compiler error



(2)

#include

void display();

void calculate();

#pragma startup calculate

#pragma  exit display

int main(){

    printf("

Sunday 11 January 2009

File handling questions in c programming with solution.



(1)What will happen if you execute following program?



#include

int main(){

    unsigned char c;

    FILE *fp;

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

    while((c=fgetc(fp))!=EOF)

         printf("%c",c);

    fclose(fp);

    return 0;

}



//test.txt

I am reading file handling in
cquestionbank.blogspot.com



Output: 

It will print the content of file
text.txt but it will enter in

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

Answer:  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 know given file is regular file, character special or it is directory?


#include "time.h"

#include "sys\stat.h"

#include "stdio.h"

void main(){

    struct stat status;

    FILE *fp;

    stat("c:\\tc\\bin",&status);

    clrscr();

    if (status.st_mode & S_IFDIR)

         printf("It is directory.\n");

    if (status.st_mode & S_IFCHR)

         printf("It is chracter file.");

    if (status.st_mode & S_IFREG)

         printf("It is reggular file.");

   

Write a c program to know read/write permission of given file.


#include "time.h"

#include "sys\stat.h"

#include "stdio.h"

void main(){

    struct stat status;

    FILE *fp;

    stat("test.txt",&status);

    clrscr();

    if (status.st_mode & S_IREAD)

         printf("You have read permission.\n");

    if (status.st_mode & S_IWRITE)

         printf("You have write permission.");

    getch();



}



Explanation:



Function  int stat(char *,

What is FILE pointer in c programming language?



FILE pointer is struct data type which has been defined in standard library stdio.h. This data type points to a stream or a null value. It has been defined in stdio.h as




typedef struct{

    short          level;

    unsigned       flags;

    char           fd;

    unsigned char  hold;

    short          bsize;

    unsigned char  *buffer, *curp;

    unsigned       istemp;

    short

What is buffer in c programming language?


Buffer is a technique which reduces number of I/O call.

What is stream in c programming language?



Stream is not a hardware it is linear queue which connect file to program and passes block of data in both direction .So it is independent of devices which we are using. We can also define stream as source of data. This source can be





(a) A file



(b) Hard disk or CD, DVD etc.



(c) I/O devices etc.





In c programming language there are two type of stream.





(a) Text streams



(b)

What is file in c programming language?

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

File handling questions in c programming language and answer with explanation



(1)What will happen if you execute following program?



#include

int main(){

    unsigned char c;

    FILE *fp;

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

    while((c=fgetc(fp))!=EOF)

         printf("%c",c);

    fclose(fp);

    return 0;

}



//test.txt

I am reading file handling in
cquestionbank.blogspot.com



Output: 

It will print the content of file
text.txt but it will enter in

What is prototype of printf function?







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