Category Archives: C Theory

All important theory content placed here!

Explain syntax of switch case statement in ‘C’ language. Also compare switch case with if else statement. 5m Dec 2009

Explain the syntax of switch case statement in ‘C’ language. Also compare the performance of switch case with if else statement. 5m Dec 2009   The Switch Statement Its objective is to check several possible constant values for an expression, something similar to what we had studied in the earlier sections, with the linking of… Read More »

What is scope of a variable ? Differentiate between Global and Local variables

What do you mean by scope of a variable ? Differentiate between Global and Local variables giving an example of each. 5m Dec 2009  Scope of a Variable Scope of a Variable means the bondaries of the variable in which it appears and can be accessible.   Global vs. Static variables: Global variables are recognized… Read More »

List and explain bitwise operators in ‘C’. 10m jun2009

List and explain bitwise operators in ‘C’. 10m The following table lists the Bitwise operators supported by C. Assume variable ‘A’ holds 60 and variable ‘B’ holds 13, then – Operator Description Example & Binary AND Operator copies a bit to the result if it exists in both operands. (A & B) = 12 i.e.,… Read More »

Explain the meaning and usage of each of the following function prototypes. jun2009

Explain the meaning and usage of each of the following function prototypes: 5×2=10m (i) getch ( )       (ii) strcmp ( )         (iii) getchar ( )       (iv) gets ( )        (v) puts ( ) (i) getch ( ) getch ( ) gets a character from console but… Read More »

Write a Program in ‘C’ to copy one file to another. The program should read the filenames at command line. 10m Jun2009

Write a Program in ‘C’ to copy one file to another. The program should read the filenames at command line. 10m Jun2009 Code: #include<stdio.h> int main(int argc,char *argv[]) { FILE *fs,*ft; int ch; if(argc!=3) { printf(“Invalide numbers of arguments.”); return 1; } fs=fopen(argv[1],”r”); if(fs==NULL) { printf(“Can’t find the source file.”); return 1; } ft=fopen(argv[2],”w”); if(ft==NULL)… Read More »

Write a Program in ‘C’ to print the following output ‘n’ rows. 10m june2009

Write a Program in ‘C’ to print the following output ‘n’ rows. For example, if n=3, the following should be output by the program: 10m june2009   #include <stdio.h> void main() { int I,J,N=3,K=0,ODD=1,SPACE; clrscr(); SPACE=N; for(I=1;I<=N;I++) { for(J=1;J<SPACE;J++) { printf(” “); } K=0; for(J=1;J<=ODD;J++) { if(J<=I) { K++; } else { K–; } printf(“%d… Read More »

Write a program that does not use the inbuilt string function to concatenate two strings 10m Jun2009

Write a program that does not use the inbuilt string function to perform the following: 10m Jun2009 (ii) To concatenate two strings Code:- #include<stdio.h> void main() { void str_concat(char*,char*,char*); char Str1[50],Str2[50],Str3[100]; clrscr(); printf(“\nENTER FIRST STRING TO CONCATE : “); scanf(“%s”,&Str1); printf(“\nENTER SECOND STRING TO CONCATE : “); scanf(“%s”,&Str2); str_concat(Str1,Str2,Str3); printf(“\nSTR1 IS : %s”,Str1); printf(“\nSTR2 IS :… Read More »

Write a program in ‘C’ to check whether the given year is leap or not. Also explain the logic of the program. 8m Dec2008

Write a program in ‘C’ to check whether the given year is leap or not. Also explain the logic of the program. 8m Dec2008 The leap year formula is: A leap year is divisable by 4, but not by 100 (except if divisable by 400.)   #include<stdio.h> void main(){ int year; clrscr(); printf(“Enter any year:… Read More »

Write a macro to find out whether the given character is lower case or not 7m Dec2008

Write a macro to find out whether the given character is lower case or not 7m Dec2008 3. (a) Write a macro to find out whether the given character is lower case or not. 7 #include <stdio.h> //#define IS_UPPER_CASE(n) ((n) >= ‘A’ && (n) <= ‘Z’) #define IS_LOWER_CASE(n) ((n) >= ‘a’ && (n) <= ‘z’)… Read More »

Write a loop that calculate sum of the n elements of the series 5m Dec2008

Write a loop that calculate sum of the n elements of the series 5m Dec2008 Write a loop that calculate sum of the n elements of the series: 5 1+ 7 +13 +19 + 25 + ……. Write the loop in 3 different ways: (i) using while loop (ii) using do-while loop   #include<stdio.h> void… Read More »