Category Archives: C Theory

All important theory content placed here!

Write a macro to demonstrate #define, #if, #else preprocessor commands. 6m Jun 2010

Write a macro to demonstrate #define, #if, #else preprocessor commands. 6    Code: #include <stdio.h> #define CHOICE 100 int my_int = 0; #if (CHOICE == 100) void set_my_int() { my_int = 35; } #else void set_my_int() { my_int = 27; } #endif main () { set_my_int(); clrscr(); printf(“%d\n”, my_int); getch(); } [codesyntax lang=”c”] #include <stdio.h> #define… Read More »

What do you understand by a decision-control statement? Give an example of each. 8m Jun 2010

What do you understand by a decision-control statement? Give an example of each. 8 In a C program, a decision causes a one-time jump to a different part of the program, depending on the value of an expression. Decisions in C can be made in several ways. The most important is with the if…else statement,… Read More »

Explain the difference between a top-down approach and a bottom-up approach in programming. 5m Jun 2010

Explain the difference between a top-down approach and a bottom-up approach in programming. 5m Jun 2010   Top-down Approach Bottom-up Approach A top-down approach is essentially the breaking down of a program to gain insight into its compositional small program (or module) in a reverse engineering fashion. A bottom-up approach is the piecing together of… Read More »

Write a program in ‘C’ to find a sum of square of odd numbers. 6m Jun 2010

Write a program in ‘C’ to find a sum of square of odd numbers :- 12 +32+ 52+ 72 +92+ +N2   Code:- #include<stdio.h> void main() { int NUM,i,j,SUM=0; clrscr(); printf(“\nENTER INTERGER NUMBER : “); scanf(“%d”,&NUM); for(i=1;i<NUM+1;i++) { if(i%2!=0) { SUM=SUM+(i*i); } } printf(“\nTHE SUM OF SQUARE OF ODD NOS. TILL %d NO. IS : %d”,NUM,SUM);… Read More »

Write a macro to find cube of a given number. 4m Jun 2010

Write a macro to find cube of a given number. 4m Code: #include<stdio.h> #define CUBE(N) (N * N * N ) void main() { int NUM; clrscr(); printf(” Enter number : “); scanf(“%d”,&NUM); printf(“\n Cube of number is : %d “,CUBE(NUM)); getch(); } [codesyntax lang=”c”] #include<stdio.h> #define CUBE(N) (N * N * N ) void… Read More »

Why C is called a middle level language? Give a flowchart to explain the program execution process. Explain each step in detail. 10m Jun 2010

Why C is called a middle level language? Give a flowchart to explain the program execution process. Explain each step in detail. 10   C is called a middle level language It is actually binding the gap between a machine-level language and high-level language. User can use C language to do System Programming (For writing… Read More »

What are the precautions that must be taken care to use macros in ‘C’? 5m Dec 2009

What are the precautions that must be taken care to use macros in ‘C’?   Caution in using macros You should be very careful in using Macros. In particular the textual substitution means that arithmetic expressions are liable to be corrupted by the order of evaluation rules (precedence rules). Here is an example of a… Read More »

Explain fscanf ( ) statements with an example. 10m Dec 2009

Explain fprintf ( ) and fscanf ( )statements with an example of each. 10m Dec 2009 fscanf() Declaration int fscanf ( FILE * stream, const char * format, … ); Description Read formatted data from stream Reads data from the stream and stores them according to the parameter format into the locations pointed by the additional arguments. The additional… Read More »

What is pointer variable? How its declared? How its address is determined? How pointer can be used to pass an entire array to a function in C? 10m Dec 2009

What is pointer variable? How is a pointer variable declared? How is the address of a pointer variable determined? How pointer can be used to pass an entire array to a function in C? Explain with the help of an example. 10 An ordinary variable is a location in memory that can hold a value.… Read More »