Find the best tutors and institutes for C Language

Find Best C Language Classes

Please select a Category.

Please select a Locality.

No matching category found.

No matching Locality found.

Outside India?

Search for topics

Give the structure of 'C' programming. Also, give significance of math.h and string.h header files.

Asked by Last Modified  

IT Courses/Programming Languages/C Language

Follow 4
Answer

28 Answers

Please enter your answer

The basic structure of a C program is : Preprocessor directives to include libraries required for execution of the program Declaration of global variables and macros main() function{ code ; } other function definitions read more

The basic structure of a C program is : 

 

Preprocessor directives to include libraries required for execution of the program

Declaration of global variables and macros

main() function{

                 code   ;

}

other function definitions

read less
Comments

The basic structure of a C program is : Preprocessor directives to include libraries required for execution of the program Declaration of global variables and macros main() function{ code ; } other function definitions 1. math.h is a header file that is to... read more

The basic structure of a C program is : 

 

Preprocessor directives to include libraries required for execution of the program

Declaration of global variables and macros

 

main() function{

 

                 code   ;

 

}

 

other function definitions

 

1. math.h is a header file that is to be include in the program if functions like sqrt(), pow(), abs() sin() etc. are to be called.

2. string.h is a header file that includes various funcitons for working on strings. These include strlen(), strcmp(), strcat(), etc.

read less
Comments

It Professional Trainer With 25 Years of Experience in It Industry

General form of c program is... Global declarationsint main(parameter list){statement sequence}return-type f1(parameter list){statement sequence}return-type f2(parameter list){statement sequence}...return-type fN(parameter list){statement sequence} This form is mainly concerned with Functions and Declarations. Significance... read more

General form of c program is...

Global declarations
int main(parameter list)
{
statement sequence
}
return-type f1(parameter list)
{
statement sequence
}
return-type f2(parameter list)
{
statement sequence
}...
return-type fN(parameter list)
{
statement sequence
}

This form is mainly concerned with Functions and Declarations.

Significance of math.h file

math.h header files drives hundreds of maths functions along with one macro. This header file returns result as double and takes double as an argument.

Significance of string.h file

string.h header file drives string related functions . This header file defines any one variable type, one macro, and number of functions.

Basically header file contains Declarations, Definitions, and Macro of related number of functions which is defined in that particular header file.

Thanks

Regards

Mahesh v Kondawar

 

read less
Comments

IT Trainer

Following is the basic structure of a C program. Documentation Consists of comments, some description of the program, programmer name and any other useful points that can be referenced later.Link Provides instruction to the compiler to link function from the library function.Definition Consists of symbolic... read more

Following is the basic structure of a C program.

Documentation Consists of comments, some description of the program, programmer name and any other useful points that can be referenced later.
Link Provides instruction to the compiler to link function from the library function.
Definition Consists of symbolic constants.
Global declaration Consists of function declaration and global variables.
main( )
{

} Every C program must have a main() function which is the starting point of the program execution.
Subprograms User defined functions.
Lets explore the sections with an example.

Write a program to print area of a circle.
In the following example we will find the area of a circle for a given radius 10cm.

Formula
The formula to compute the area of a circle is πr2 where π is PI = 3.1416 (approx.) and r is the radius of the circle.

Lets write the C code to compute the area of the circle.

 

#include <stdio.h>

#define PI 3.1416

float area(float r);

int main(void)
{
float r = 10;
printf("Area: %.2f", area(r));
return 0;
}

float area(float r) {
return PI * r * r;
}
The above code will give the following output.

Area: 314.16
Different sections of the above code
Documentation
This section contains a multi line comment describing the code.

In C, we can create single line comment using two forward slash // and we can create multi line comment using /* */.

Comments are ignored by the compiler and is used to write notes and document code.

Link
This section includes header file.

#include <stdio.h>
We are including the stdio.h input/output header file from the C library.

Definition
This section contains constant.

#define PI 3.1416
In the above code we have created a constant PI and assigned 3.1416 to it.

The #define is a preprocessor compiler directive which is used to create constants. We generally use uppercase letters to create constants.

The #define is not a statement and must not end with a ; semicolon.

Global declaration
This section contains function declaration.

float area(float r);
We have declared an area function which takes a floating number (i.e., number with decimal parts) as argument and returns floating number.

main( ) function
This section contains the main() function.

int main(void)
{
float r = 10;
printf("Area: %.2f", area(r));
return 0;
}
This is the main() function of the code. Inside this function we have created a floating variable r and assigned 10 to it.

Then we have called the printf() function. The first argument contains "Area: %.2f" which means we will print floating number having only 2 decimal place. In the second argument we are calling the area() function and passing the value of r to it.

Subprograms
This section contains a subprogram, an area() function that is called from the main() function.

float area(float r) {
return PI * r * r;
}
This is the definition of the area() function. It receives the value of radius in variable r and then returns the area of the circle using the following formula PI * r * r.


The math.h header defines various mathematical functions and one macro. All the functions available in this library take double as an argument and return double as the result. 

string.h is the header in the C standard library for the C programming language which contains macro definitions, constants and declarations of functions and types used not only for string handling but also various memory handling functions; 

read less
Comments

Tutor

Math.h is a header file that contains all the math related functions like finding square root, absolute values etc. While string.h is a header file which contains all functions to perform string related operation
Comments

Tutor

#include<stdio.h> //header file main() // entry point for a program { // variables declaration //logic which you want to achieve } math.h is a header file for working with mathmatical functions like abs() sum() etc.. string.h is also header file for working with string functions like strupr(),strlwr()... read more

#include<stdio.h> //header file

main() // entry point for a program

{

// variables declaration

//logic which you want to achieve

}

math.h is a header file for working with mathmatical functions like abs() sum() etc..

string.h is also header file for working with string functions like strupr(),strlwr() etc.. 

without writing any manual code you can use these functions in your program for your purpose

ex: strlwr("nani") is automatically converted to "NANI" which is the output

read less
Comments

Tutor

Hello IshwariWe know we have already defined data types like int, char, float, double.Let's take intWhen we declare int i ;It simply means an area of 2 Bytes(architecture dependent) gets allocated and the area is named as i and as our houses get some address in a street, in the same manner, this area... read more

Hello Ishwari
We know we have already defined data types like int, char, float, double.
Let's take int
When we declare
int i ;
It simply means an area of 2 Bytes(architecture dependent) gets allocated and the area is named as i and as our houses get some address in a street, in the same manner, this area will also have an address.

Now if we want some area which must contain say some 5 Bytes and that area has to be divided into 3 areas.
we want to give the first division to an int , the 2nd division to a char, the 3rd division to another int.
So this type of data type is not already defined.

So we need to make a data type like this on our own.

How to do that?
We use structure.

struct datatype
{
    int i;
    char c;
    int j;
};

Now if we declare
datatype x;
Then x will have our desired memory allocation.


Math.h 
has function definitions of the mathematical functions that we use.
example : pow()

Similarly, string.h has functions that we use t manipulate strings. 
 

read less
Comments

Documentation Section Link section Definition section Global Declaration Section Main() function section { Declaration part Executable part } Sub program section read more

Documentation Section

Link section

Definition section

Global Declaration Section 

Main() function section

{

Declaration part

Executable part

}

Sub program section
read less
Comments

Computer Science Teacher 15 Yrs

A C program basically consists of the following parts − Preprocessor Commands Functions Variables Statements & Expressions Comments Let find a simple code that would print the words "Hello World" : #include <stdio.h> int main() { /* my first program in C */ printf("Hello,... read more

A C program basically consists of the following parts −

  • Preprocessor Commands
  • Functions
  • Variables
  • Statements & Expressions
  • Comments

Let find a simple code that would print the words "Hello World" :

#include <stdio.h>

int main() {
   /* my first program in C */
   printf("Hello, World! \n");
   
   return 0;
}

Let us take a look at the various parts of the above program −

  • The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation.

  • The next line int main() is the main function where the program execution begins.

  • The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program.

  • The next line printf(...) is another function available in C which causes the message "Hello, World!" to be displayed on the screen.

  • The next line return 0; terminates the main() function and returns the value 0.

significance of math.h and string.h header files.

math.h is a header file in the standard library of the C programming language designed for basic mathematical operations. Most of the functions involve the use of floating point numbers. C++ also implements these functions for compatibility reasons and declares them in the header

string.h is the header in the C standard library for the C programming language which contains macro definitions, constants and declarations of functions and types used not only for string handling but also various memory handling functions

For details study please contact me.

read less
Comments

Tutor

First of all, let me correct the person to ask the question. What is correct according to a computer programming language is that its #include<math.h> And not just #math. H, which is programmatically wrong.Anyway, as the question comes, well.In a C program, #include<math.h> is a header file... read more

First of all, let me correct the person to ask the question. What is correct according to a computer programming language is that its #include<math.h> And not just #math. H, which is programmatically wrong.
Anyway, as the question comes, well.
In a C program, #include<math.h> is a header file in the standard library of the C programming language designed for basic mathematical operations. Most of the functions imply the use of floating point numbers. C++ also implements these functions for congeniality reasons and declares them into the header file. One can hence use functions of math.h in a C program to calculate the absolute value of a number, calculating logarithms, using trigonometric functions to calculate sine, the cosine of an angle, etc.
The math.h header thus defines various mathematical functions and one macro. All the features available in this library take double as an argument and return double as a result.

read less
Comments

View 26 more Answers

Related Questions

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Some Tricky Questions in C
Can you write two functions in which one executes before main function and other executes after the main function? #pragma startup #pragma exit Where, priority is optional integer value.For user priority...

Sahana D. | 16 Feb

0 0
0

Program to swap the value of two variables without using third variable(simplest way)...
int main() { int a=10,b=20; printf("values of a before swap ="%d,a); printf("values of b before swap ="%d,b); a=a+b; b=a-b; a=a-b; printf("******************"); printf("values of a after swap...

Rohan | 17/11/2018

2 0
1

Advantages of C++ Language
Advantages of C++ - C++ is a profoundly convenient dialect and is frequently the dialect of decision for multi-gadget, multi-stage application advancement. - C++ is a protest situated programming dialect...

Recommended Articles

Applications engineering is a hot trend in the current IT market. An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company s manufacturing, marketing, sales, and customer...

Read full article >

Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system s storage capacity and you can t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...

Read full article >

Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...

Read full article >

Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...

Read full article >

Looking for C Language Classes?

Find best C Language Classes in your locality on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you

Find Best C Language Classes?

Find Now »

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 25 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 6.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more