Skip to main content

Functions in C-Computer Science-Important topic in C

 Function in C

->Watch this for FUN - Funny job interview

Are you getting bored with online lectures?

->Watch this - When online lectures are boring 

Function in C is a very important topic in C. The library in C has many in-built functions like printf, scanf, etc.

Every C program has at least one main function where the code starts executing. 

The main function is declared using int main().



Now, we'll be going to see various types of function declaration, their return types, etc.

There are three main things for executing a function in C programming language which are its declaration, its calling, and its execution.

The return type of function includes primitive and derived data types. For data types, refer to this.

Function declaration:

         There are two ways where you can declare/call a function.

Way 1:

Declaring outside the main, globally,

int(return type) fun(data type of arguments);

For example,

void fun(int, char); // Function declaration

int main()

{

 int a=5;

 char b='d';

 fun(a,b); // Function calling

 return 0;

}

void fun(int a,char b)

{

 printf("%d\n%c",a,b); // Function execution

}

However only this,

int main()

{

 int a=5;

 char b='d';

 fun(a,b); // Function calling

 return 0;

}

void fun(int a,char b)

{

 printf("%d\n%c",a,b); // Function execution

}

is wrong.

Way 2:

Calling it inside the void main/int main function, but for executing this function, you have to execute it before the function in which you are calling the latter,
void fun(int a, int b)

{

    printf("%d\n",a+b); // Execution is possible only if it is written before the function in which it is called

}

int main()

{

   int a=3,b=9;

   fun(a,b); // Calling the function "fun"

   return 0;

}

In the above code, you don't have to declare the function "fun" as it is present before the function in which it is called.


->Watch this for FUN - Funny job interview

Are you getting bored with online lectures?

->Watch this - When online lectures are boring 

<><><><><><><>

Hope you have learned
something new 
today.
Visit other posts 
by clicking on 
LABELS.
<><><><><><><>
Do follow and comment
and don't forget to
SUBSCRIBE.

<><><><><><><> 

Comments

  1. Online learning is an educational mode allowing students to take part in different courses and programs using the internet. In online tuition, students don't need to waste their time going to the lecture halls or classrooms, rather they can decide to learn whatever from any part of the world. For online tuitions you can call - +91-9654271931.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to make your header file in C?-Important topics in C-computer science/Information technology

Making your header file ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   Yes, you can make your header file, as we use the standard header files which are stored in your system, the same way we can also make our. So, let's see how? Step 1 . Define the functions which you will gonna use in the program in some file named (hello.h). Step 2 . In the program file, use #include"hello.h" for including that header file which has been saved by you. <><><><><><><> That's it, you are done, now you can use the functions which you have declared in the hello.h file anywhere in the program. Watch this for FUN -  Funny job interview Are you getting bored with online lectures? Watch this -  When online lectures are boring <><><><><><><> I hope you  have  learned something today. Visit other posts by  clicking

Advanced File handling operations in C-Important topics in C-computer science/Information technology

File handling in C ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   H ere in this blog, we are going to learn how to handle any file on the Computer using this file handling in the C programming language tutorial. So, what's File handling in C?. So, Let's get started with this. File handling in C is an important concept in C programming language which is itself the mother language of all the high-level programming language. Through mastering this, you can master any file in your Personal computer with its content by writing, appending, and doing much more what you can. A file represents a sequence of bytes on the disk where a group of related data is stored in the memory. The file is created for the permanent storage of data.  It is a readymade structure.  In C language, we use a structure pointer of the file type to declare a file which is [FILE *fp] (where fp is the

Standard header files in C programming language-Important topics in C-computer science/Information technology

Standard header files in C programming language ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   Header files are the files that contain the set of predefined library functions that can be used anywhere while writing the program. That's why they become handy in use for their operations while writing a C program. Even you can make your header file. The following header files are the standard ones: 1. stdio.h                This header file is used for various input/output functions like printf() , scanf() ,etc. <><><><><><><> 2. stdlib.h                This header file is mainly used for dynamic memory allocation like malloc() , calloc() , realloc() , free() and even for some functions like abs() [for absolute value of the number] and atoi() [ for converting string to a number] and even more. <><><><><><><&g

What is the general form of a C program in C programming?-Computer Science-Important topic in C

General form  ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   Generally, the C program starts with the header files , followed by preprocessor directives (like macros), and then followed by the functions or the variables to be declared globally which is again followed by the main function for starting the execution. #include<stdio.h> // Header files #define a 10 // Preprocessor directives int x=10; // Global variable int main() // main function { }

Beginning with Computer science??-computer science/Information technology

Are you a beginner in Computer Science? ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   No worries!! Computer Science-Is it a NO or a YES? What do you think? let’s find out! Computer science is the study of computation and information. Computer science has impacted a lot in our daily lives, whether we have to design software or to book something online for shopping. Computer Science Computer science is the medium of all the online services that are evolving throughout the world. So, now you wanna ask me what is computer science build of? Computer science is not just about the front-end that you see in your daily lives but it is built on tonnes and tonnes of codes which run and execute in the back-end part which is not seen-able. Those parts of the code consist of languages generally called programming languages (generally because HTML, CSS are not programming languages). Now you need to know

Call by value and call by reference in C-Important topics in C-computer science/Information technology

Call by value and Call by Reference  in C ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   There are two ways to call out a function in C and those are Call by Value and Call by Reference. So, what they are, let's find out. <><><><><><><> Call by value :                                 Here the values in the function get copies of the original values but they don't get a revert to the modified value.  For example:                      void swap(int x, int y)                      {                             int temp=x;                             x=y;                             y=temp;                      }                      int main()                     {                      int a=5,b=7;                      swap(a,b);                      printf("%d %d\n",a,b);// Would print 5 7 although the values got modified in the funct

Data types in C-Computer Science-Important topics

 Data Types in C ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   Data types are the building blocks of any programming language. It is the most important topic in C, without data types there couldn't be any foundation of C programming language. So, now let's move on to the types of Data types in C. <><><><><><><> There are three types of data types in C: 1) Primitive data types. 2) Derived data types. 3) User-defined data types. So, let's explore what each one is about: 1) Primitive Data Types Primitive data types in C programming language includes  int, char, float, void . The int data type is used for the declaration of integer variables like: int x=10; // integer x takes value 10 The char data type is used for the declaration of character variables like: char x='a'; // character x takes value a The char data type is used for th

Structures in C programming language-Important topics in C-computer science/Information technology

S tructures in C programming language ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   Structures in C is a very important topic in the C programming language as it can store multiple data types due to which it comes under the user-defined data type.  By the multiple data types, I mean that it can store data types like int, float, char, double, etc. The declaration of a structure in C goes like : struct name{ // name is Name of the structure int n,m; //int data type float f;  //float data type char a[20000];  //character data type }; NOTE :- You cannot initialize any data type in structures , like struct name{ int n=3,m=2; // ERROR float f=3.5; //ERROR }; By using structures, it would become very easy to store multiple information of any kind. For using structures in the int main in C, let's take the example of storing the ID, NAME of the student, the program goes like, #include<stdio.

Vectors in C++-Important topics in C++-Computer science

  Vectors in C++ ->Watch this for FUN -  Funny job interview Are you getting bored with online lectures? ->Watch this -  When online lectures are boring   Vectors in C++ are a sequence container class that implements the dynamic size of the array to store things without caring for its size. ****** Array vs Vectors An array although is a static allocation where size is fixed, but in Vectors, the size is not fixed due to its dynamic nature.  ***** Declaration of Vectors std:: vector<int> vec; //under #include<vector> library ***** Important functions of vectors are: emplace() ->vec.emplace(position,value) inserts the value at the specified position. emplace_back() ->vec.emplace_back(value) inserts the value at the end of the vector. insert() ->vec.insert(position,value) inserts the value at the front of the position given in the function. resize() ->vec.resize(value), resizes the vector's size to the value. reserve() ->vec.reserve(value) reserves the

Translate