Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
7.2k views
in Computer by (43.6k points)
closed by

Explain the structure of a ‘C’ program with example.

1 Answer

+1 vote
by (43.1k points)
selected by
 
Best answer

Structure of ‘C’ Program:

Before understanding the structure of a ‘C’ program you must know these important points:

  • ‘C’ is a case sensitive language, it means all the keywords must be written in lower case.
  • Key-words can’t be used as a variable or function name.
  • Every instruction should end with (;) sign.
  • Preprocessor directives (required) should be there in the beginning.
  • Function main () is must for a program.

Now to write a program in ‘C’ we need to follow these steps: Define preprocessor directives (include header files according to prototype functions, standard I/O library functions to be used).

  • Open function main ()
  • Assign data types and variables.
  • Define the body of the function
  • End the function main ()

Example

/* harsh.c : first example for students */

# include

void main ()

{ int a = 10, b = 15, c;

printf (“Hellow students \n”); c = a + b ;

printf (“The sum of % d and % d is % d” , a, b, }

In the above example the first line /*harsh.c: first example for students */ is a comment and non-executable. Comments in ‘C’ begins with (/*) and ends with (*/).

Second-line

#include

is a preprocessor directive. The preprocessor processes the ‘C’ program before the compiler. Here stdio.h is a header file consists of standard I/O functions. A header file related to the functions used in program should be included at the beginning.

The line void main() indicates “the beginning of the program”. The compilation of the program starts from main () function.

{, the symbol indicates the beginning of the main () function

The line int a = 10, b = 15, C; is for declaration of variables and data types.

Lines

printf (“Hellow students \n”); C = a + b. printf (“The sum of % d and % d is % d” , a, b, c); are the body of the program.

and symbol ‘}’ indicates end of main ( ) function.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jun 21, 2022 in Computer by ParneetNain (43.6k points)
0 votes
1 answer
asked Jun 21, 2022 in Computer by ParneetNain (43.6k points)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...