The document discusses functions in C programming. It defines functions as self-contained blocks of code that perform a specific task. Functions make a program modular and easier to debug. There are four main types of functions: functions with no arguments and no return value, functions with no arguments but a return value, functions with arguments but no return value, and functions with both arguments and a return value. Functions are called by their name and can pass data between the calling and called functions using arguments.
This document discusses functions in C++. It defines what a function is and explains that functions are the building blocks of C++ programs. Functions allow code to be reused, making programs easier to code, modify and maintain. The document covers function definitions, declarations, calls, parameters, return types, scope, and overloading. It also discusses local and global variables as well as pass by value and pass by reference.
Functions allow programmers to structure C++ programs into modular segments of code to perform individual tasks. There are two types of functions: library functions and user-defined functions. User-defined functions are defined using a return type, function name, and parameters. Functions can be called by value or by reference and can also be inline, recursive, or friend functions.
A function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions. You can divide up your code into separate functions.
The document discusses C programming functions. It provides examples of defining, calling, and using functions to calculate factorials, Fibonacci sequences, HCF and LCM recursively and iteratively. Functions allow breaking programs into smaller, reusable blocks of code. They take in parameters, can return values, and have local scope. Function prototypes declare their interface so they can be called from other code locations.
A function is a block of code that performs a specific task. Functions allow for modularity and code reuse in a program. There are several key aspects of functions:
1. Functions are defined with a return type, name, and parameters. The general format is return_type function_name(parameter list).
2. Parameters allow functions to accept input from the caller. There are two ways parameters can be passed: call by value or call by reference.
3. Variables declared inside a function are local, while those declared outside are global and visible to all code. Local variables exist only during the function's execution.
4. Functions can call themselves recursively to repeat a task, with a base
Pointer is a variable that stores the memory address of another variable. It allows dynamic memory allocation and access of memory locations. There are three ways to pass arguments to functions in C++ - pass by value, pass by reference, and pass by pointer. Pass by value copies the value, pass by reference copies the address, and pass by pointer passes the address of the argument. Pointers can also point to arrays or strings to access elements. Arrays of pointers can store multiple strings. References are alternative names for existing variables and any changes made using the reference affect the original variable. Functions can return pointers or references.
The document discusses functions in C++, including how they can be used to break programs into modular and reusable parts. Functions allow for passing of data between caller and callee functions through arguments. There are different ways functions can handle arguments, including call by value, call by address, and call by reference.
Operator & control statements in C are used to perform operations and control program flow. Arithmetic operators (+, -, *, /, %) are used for mathematical calculations on integers and floating-point numbers. Relational operators (<, <=, >, >=, ==, !=) compare two operands. Logical operators (&&, ||, !) combine conditions. Control statements like if-else, switch, while, for, break, continue and goto alter program execution based on conditions.
Introduction to control structure in C Programming Language include decision making (if statement, if..else statement, if...else if...else statement, nested if...else statement, switch...case statement), Loop(for loop, while loop, do while loop, nested loop) and using keyword(break, continue and goto)
The document discusses functions in C programming. It defines a function as a self-contained block of code that performs a specific task. Functions make code more modular and reusable. There are two types of functions: standard/library functions and user-defined functions. Functions can take input parameters and return values. Functions are an essential part of program structure in C as they help organize code and logic.
Functions allow programmers to break programs into smaller, reusable parts. There are two types of functions in C: library functions and user-defined functions. User-defined functions make programs easier to understand, debug, test and maintain. Functions are declared with a return type and can accept arguments. Functions can call other functions, allowing for modular and structured program design.
BRANCHING STATEMENTS
if statement
if – else statement
if – else if ladder
Nested if
Goto
Switch case
programs
output
flowchart
Branching / Decision Making Statements
The statements in the program that helps to transfer the control from one part to other parts of the program.
Facilitates program in determining the flow of control
Involves decision making conditions
See whether the condition is satisfied or not
If statement; Execute a set of command line or one command line when the logical condition is true.
It has only one option
syntax with flowchart
If else if ladder; Number of logical statements are checked for executing various statement
If the first condition is true the compiler executes the block followed by first if condition.
If false it skips the block and checks for the next logical condition followed by else if.
Process is continued until a true condition is occurred or an else condition is satisfied.
Switch case; Multiway branch statement
It only requires one argument of any type, which is checked with number of cases.
If the value matches with the case constant, that particular case constant is executed. If not the default statement is executed.
Break statement – used to exit from current case structure
Nested if else; When a series of decisions are involved we use more than one if-else statement.
If condition is true control passes to first block i.e., if block. In this case there may be one more if block.
If condition is false control passes to else block. There we may have one more if block.
The document discusses C functions, including their definition, types, uses, and implementation. It notes that C functions allow large programs to be broken down into smaller, reusable blocks of code. There are two types of functions - library functions and user-defined functions. Functions are declared with a return type, name, and parameters. They are defined with a body of code between curly braces. Functions can be called within a program and allow code to be executed modularly and reused. Parameters can be passed by value or by reference. Functions can return values or not, and may or may not accept parameters. Overall, functions are a fundamental building block of C that improve code organization, reusability, and maintenance.
The document discusses various conditional statements in C language including if, if-else, nested if-else, ladder else-if, switch case statements. It provides syntax and examples to check eligibility, find the greatest among numbers, print day name from number. Goto statement is also covered which is used to directly jump to a label in a program. Break and continue statements help control loop execution.
Virtual functions allow functions to be overridden in derived classes. The virtual keyword before a function in the base class specifies that the function can be overridden. When a virtual function is called using a base class pointer, the version from the most derived class will be executed due to late binding. This allows runtime polymorphism where the function call is resolved based on the actual object type rather than the pointer variable type.
A large program can be divided into smaller subprograms or functions. Functions make a program easier to write, read, update and debug by dividing it into self-contained tasks. Functions allow code to be reused and are called by the main program. Functions may accept arguments from the main program and return values to the main program. This allows two-way communication between functions and the main program.
A pointer is a variable that stores the memory address of another variable. Pointers allow functions to modify variables in the caller and are useful for handling arrays and dynamic memory allocation. Pointers contain the address of the memory location they point to. Pointer variables can be declared to hold these memory addresses and can then be used to indirectly access the value at the addressed location.
1. A function is a block of code that performs a specific task. Functions allow programmers to split a large program into smaller sub-tasks and call them multiple times.
2. There are two main types of functions - library functions provided by the standard library, and user-defined functions created by the programmer.
3. Functions make programs easier to write, read, update and debug by splitting them into smaller, well-defined tasks.
This document discusses different types of functions in C programming. It provides examples of functions with no arguments and no return value, functions with arguments and no return value, functions with arguments and return value, functions with no arguments but return value, and functions that return multiple values. The examples demonstrate how to define and call each type of function.
The document provides examples of using functions in C programming. It explains what a function is, how to define a function with return type, parameters, and body. It also discusses function declaration, calling a function, function arguments, and the difference between call by value and call by reference. Examples are given to demonstrate defining, declaring, calling functions, and how call by value does not actually change the argument values unlike call by reference. The document also briefly mentions formal parameters and how they behave like local variables inside a function.
There are two ways to initialize a structure:
1. Initialize structure members individually when declaring structure variables:
struct point {
int x;
int y;
} p1 = {1, 2};
2. Initialize an anonymous structure and assign it to a variable:
struct point p2 = {3, 4};
Structures allow grouping of related data types together under one name. They are useful for representing records, objects, and other data aggregates. Structures can contain nested structures as members. Arrays of structures are also possible. Structures provide data abstraction by allowing access to their members using dot operator.
The document discusses functions in C programming. It defines what a function is and explains why functions are used to avoid duplicating code and make programs easier to design, understand and maintain. It describes the different types of functions like pre-defined and user-defined functions. It also covers function prototypes, parameters, return values, recursion, library functions and pointers.
The document discusses functions in C programming. It defines what a function is, how functions are declared and defined, how to pass arguments to functions, and different ways to call functions. It provides examples of using functions to calculate factorials, Fibonacci series, find the highest common factor and lowest common multiple of two numbers, and sum the digits of a number recursively. Various ways of implementing functions using loops, recursion, and by passing arguments are demonstrated through code examples.
This document discusses functions in C programming. It defines what a function is and explains why we use functions. There are two types of functions - predefined and user-defined. User-defined functions have elements like function declaration, definition, and call. Functions can pass parameters by value or reference. The document also discusses recursion, library functions, and provides examples of calculating sine series using functions.
The document discusses functions in C programming. It defines what a function is and describes the key parts of a function like the return type, function name, parameters, and function body. It provides examples of different types of functions like functions with and without arguments and return values. It also explains how parameters can be passed by value or by reference in functions and gives examples. Finally, it briefly mentions function scopes in C.
The document discusses functions in C programming. It defines a function as a block of code that performs a specific task. There are two types of functions: predefined standard library functions and user-defined functions. The key aspects of a function are its declaration, definition, and call. Functions can be used to break a large program into smaller, reusable components. Parameters can be passed to functions by value or by reference. Recursion is when a function calls itself, and is used in algorithms like calculating factorials. Dynamic memory allocation allows programs to request memory at runtime using functions like malloc(), calloc(), realloc(), and free().
The document discusses functions in C programming. It defines functions and explains their various parts like declaration, definition, and invocation. It also differentiates between function declaration and definition. Various types of functions are classified based on their inputs and outputs. The key differences between call by value and call by reference are explained with examples. Advantages of pass by reference are also mentioned.
The document discusses functions in C programming. It defines what a function is and explains the advantages of using functions, such as avoiding duplicate code and improving reusability. It describes the different parts of a function - declaration, definition, and call. It explains user-defined and standard library functions. It also covers parameter passing techniques (call by value and call by reference), recursion, and dynamic memory allocation using functions like malloc(), calloc(), realloc(), and free().
The document presents information about functions in the C programming language. It discusses what a C function is, the different types of C functions including library functions and user-defined functions. It provides examples of how to declare, define, call and pass arguments to C functions. Key points covered include how functions allow dividing a large program into smaller subprograms, the ability to call functions multiple times, and how functions improve readability, debugging and reusability of code. An example program demonstrates a simple C function that calculates the square of a number.
1. Functions allow programmers to break programs into smaller, self-contained subprograms, making code more modular and reusable.
2. There are four types of functions: those with no arguments and no return value, no arguments but a return value, arguments but no return value, and arguments with a return value.
3. Functions can be user-defined or library functions provided in standard libraries that perform common tasks like input/output and mathematics. Functions must be declared, defined, and called properly in a program.
This document discusses modular programming and functions in C programming. Modular programming involves separating a program's functionality into independent, interchangeable modules. There are advantages to this approach such as improved manageability, reusability, and collaboration between programmers.
The document then discusses functions in C programming. Functions allow programmers to divide a program into reusable modules. There are two types of functions - standard library functions defined in header files, and user-defined functions. User-defined functions have advantages like making programs easier to understand, maintain, and debug. The key parts of a user-defined function are the declaration, definition, and call. Functions can take arguments, return values, and be used recursively. Arrays and 2D arrays
This document discusses functions in C programming. It defines a function as a section of code that performs a specific task. Functions make programming simpler by splitting problems into smaller, more manageable sub-problems. The key advantages are that problems can be viewed at a smaller scope, program development is faster, and programs are easier to maintain. There are two types of functions - library functions provided by the language and user-defined functions written by the programmer. Functions can take parameters, perform operations, and return values. Well-structured functions are important for organizing code and solving complex problems.
The document discusses functions in C programming. It defines what a function is and explains that functions can be used to break a large program into smaller modular pieces of code that can be reused. The key points covered include: defining functions with return types, parameters, and bodies; declaring functions; calling functions by passing arguments; and passing arguments by value vs reference. Examples are provided to demonstrate creating, calling, and passing arguments to functions. Recursion is also discussed as a special case where a function calls itself.
Programming Fundamentals Functions in C and typesimtiazalijoono
Programming Fundamentals
Functions in C
Lecture Outline
• Functions
• Function declaration
• Function call
• Function definition
– Passing arguments to function
1) Passing constants
2) Passing variables
– Pass by value
– Returning values from functions
• Preprocessor directives
• Local and external variables
The document discusses functions in C programming. It defines a function as a block of code that performs a specific task. Some key points:
- Functions allow breaking a program into smaller and reusable parts. The main() function is required in every C program.
- Functions are declared with a return type, name, and parameters. They are defined with a block of code enclosed in curly braces.
- Functions can be called from other functions and can call themselves recursively. However, a function cannot be defined within another function.
- By default, C uses call-by-value to pass arguments to functions. This means changes to parameters do not affect the original arguments. Call-by-reference uses
The document discusses functions and pointers in C programming. It defines functions as reusable blocks of code that perform a specific task. Functions are declared with a return type, name, parameters, and body. Parameters can be passed by value or reference. Pointers are variables that store memory addresses. Pointer arithmetic and pointers with arrays are also covered. The document provides examples of different types of functions like those with and without return values and parameters. Recursion, where a function calls itself, and pointers are demonstrated through code examples.
This document outlines Cisco's CCNA Security certification program. It discusses the growing importance of security roles in networking and how CCNA Security provides skills in secure router configuration, AAA, ACLs, firewalls, IPS, and VPN implementation to prepare students for entry-level security jobs or more advanced certifications like CCSP. The CCNA Security certification can be obtained by passing the Implementing Cisco IOS Network Security (IINS) exam after obtaining CCNA certification.
Arrays in C allow storing multiple values of the same data type in a single variable. An array is declared with the data type, array name, and size. Elements in an array are accessed using indexes that run from 0 to size-1. Multidimensional arrays can also be declared to store arrays of arrays.
This document discusses arrays in C language. It defines an array as a data structure that stores a collection of similar data types. It describes how to declare, create and initialize single and multi-dimensional arrays in C. It also explains that arrays have a fixed size once declared, and elements can be accessed via indexes. Multidimensional arrays can be thought of as arrays of arrays.
This document defines and explains cloud computing. Cloud computing refers to storing and accessing data and programs over the Internet instead of a computer's hard drive. It discusses the history of cloud computing beginning in the 1950s. The key components of cloud computing are clients, distributed servers located in data centers, and a central server that administers the system. There are different service models depending on what is provided via the cloud. Cloud services can be deployed in public, private, community, or hybrid configurations.
The document discusses the differences between polymorphism achieved through virtual methods (runtime polymorphism) vs templates (compile-time polymorphism) in C++. It provides examples of implementing the same functionality using both approaches and compares their performance, type safety, and other characteristics. It also discusses best practices for combining templates and inheritance to leverage their strengths while avoiding weaknesses.
ASP.NET allows for simplified and modular web development through features like server-side coding, rich web forms, drag-and-drop design, and reusable server controls. The page lifecycle in ASP.NET involves events like init, load, and render that occur on both the client and server sides. State management is provided through view state stored on the client and session/application state stored on the server. Master pages allow content to be templated for reuse across pages. A web application project compiles all pages into a single DLL for improved performance compared to a web site project.
Dennis Ritchie and Ken Thompson developed the C language between 1969 and 1973 at Bell Labs to re-implement the UNIX operating system. The first C program example in K&R was "Hello, World!". C language includes lowercase and uppercase letters, decimal digits, and graphic characters in its character set and has 32 keywords. C is widely used today for system programming and website programming.
HTML is used to create web documents and consists of text and markup tags to define structure, appearance, and hyperlinks. There are two types of tags: container tags define sections of text using start and end tags, and empty tags represent single occurrences like line breaks. CSS is used to style HTML documents and consists of rules with selectors and declarations specifying properties and values to control styling. PHP is a widely used server-side scripting language with roots in C and C++ that is commonly used with MySQL, a popular open-source database, to create dynamic web applications.
HTML is used to create web documents through tags that define structure and formatting. There are two types of tags - container tags that define sections of text and empty tags that represent single instructions. Various text editors and WYSIWYG tools can be used to author HTML documents, which have a head and body structure. Graphics, audio, video, and other multimedia can be added through file formats like GIF, JPG, PNG, AVI, MOV, MIDI, and MP3. Additional functionality is provided through plug-ins like Flash, Shockwave, and QuickTime. XML is used to consistently present various data types, while VRML creates 3D virtual reality environments.
This document defines and explains cloud computing. Cloud computing refers to storing and accessing data and programs over the Internet instead of a computer's hard drive. It discusses the history of cloud computing beginning in the 1950s. The key components of cloud computing are clients, distributed servers located in data centers, and a central server that administers the system. There are different service models depending on what is provided via the cloud. Cloud services can be deployed in public, private, community, or hybrid models. The popularity of cloud computing is due to reduced complexity, scalability, and not needing to purchase software licenses.
C++ was created by Bjarne Stroustrup and combines elements of C and Simula67. It supports both low-level efficiency and high-level coding through object-oriented programming principles like encapsulation, polymorphism, and inheritance. C++ programs organize code around data and define types that specify which operations can be performed on that type of data.
JavaScript allows for interactivity on web pages by manipulating HTML elements and reacting to user actions. It is a scripting language that runs in web browsers and is used to validate form input, detect browsers, and create dynamic content. JavaScript code is embedded within HTML pages and works together with HTML for content and CSS for presentation.
The document provides information about WordPress meetups held on the first Saturday of each month. The upcoming meetup will focus on WordPress and CSS, covering new CSS technologies, plugins, frameworks, and tools. Future meetups will discuss page builders and themes. The meetups involve introductions from attendees, questions, demonstrations, and discussions. CSS is described as important for styling websites built with WordPress. Inline CSS, page-wide CSS, site-wide CSS, and plugins can be used to add styling.
The document provides information about WordPress meetups held on the first Saturday of each month. The upcoming meetup will focus on WordPress and CSS, covering new CSS technologies, plugins, frameworks, and tools. Future meetups will discuss page builders and themes. The meetups involve introductions from attendees, questions, demonstrations, and discussions. CSS is described as important for styling websites built with WordPress. Inline CSS, page-wide CSS, site-wide CSS, and plugins can be used to add styling. Free plugins like SiteOrigin CSS Editor and paid options like CSSHero allow editing CSS for WordPress sites.
PHP stands for Hypertext Preprocessor and originated as a scripting tool that has become popular for web development due to being free and having frameworks to simplify development. Major sites using PHP include Twitter and Facebook. ASP stands for Active Server Pages and allows coding using any .NET supported language, increasing its popularity among .NET developers, as well as Microsoft's early domination of the browser market with Internet Explorer.
The document discusses a CCNA Security evening seminar that provides an overview of the course. It describes the skills and knowledge verified by the CCNA Security certification, including securing Cisco devices and technologies, administering security policies, and identifying network risks. The seminar also outlines the course content, such as securing routers, implementing AAA, using ACLs to mitigate threats, and configuring firewalls, IPS, and site-to-site VPNs using Cisco devices. The target audience is described as career starters seeking entry-level security skills and IT professionals looking to expand their skills.
Cloud computing provides on-demand access to IT resources and applications from the internet. It offers data storage, infrastructure, and application resources that users can access from anywhere. There are three primary service models - Infrastructure as a Service (IaaS) provides virtual machines and storage, Platform as a Service (PaaS) provides development tools and runtime environments, and Software as a Service (SaaS) provides applications users can access through the internet.
This document defines and explains cloud computing. Cloud computing allows users to access software and storage over the internet rather than locally on their own computer. It discusses the history of cloud computing concepts dating back to 1950. The key components of cloud include clients, distributed servers located in datacenters, and a central server that administers the system. There are different service models depending on what is provided via the cloud. Cloud services can be deployed in public, private, community, or hybrid models. The popularity of cloud computing is due to advantages like reduced complexity, scalability, and not needing to purchase and maintain own software/servers.
The document describes a simple "Hello World" C program that prints three strings to the screen. It contains the main() function which uses printf statements to output the text. Comments provide explanations of key elements like header files, escape characters, and functions.
Ardra Nakshatra (आर्द्रा): Understanding its Effects and RemediesAstro Pathshala
Ardra Nakshatra, the sixth Nakshatra in Vedic astrology, spans from 6°40' to 20° in the Gemini zodiac sign. Governed by Rahu, the north lunar node, Ardra translates to "the moist one" or "the star of sorrow." Symbolized by a teardrop, it represents the transformational power of storms, bringing both destruction and renewal.
About Astro Pathshala
Astro Pathshala is a renowned astrology institute offering comprehensive astrology courses and personalized astrological consultations for over 20 years. Founded by Gurudev Sunil Vashist ji, Astro Pathshala has been a beacon of knowledge and guidance in the field of Vedic astrology. With a team of experienced astrologers, the institute provides in-depth courses that cover various aspects of astrology, including Nakshatras, planetary influences, and remedies. Whether you are a beginner seeking to learn astrology or someone looking for expert astrological advice, Astro Pathshala is dedicated to helping you navigate life's challenges and unlock your full potential through the ancient wisdom of Vedic astrology.
For more information about their courses and consultations, visit Astro Pathshala.
How to Add Colour Kanban Records in Odoo 17 NotebookCeline George
In Odoo 17, you can enhance the visual appearance of your Kanban view by adding color-coded records using the Notebook feature. This allows you to categorize and distinguish between different types of records based on specific criteria. By adding colors, you can quickly identify and prioritize tasks or items, improving organization and efficiency within your workflow.
Credit limit improvement system in odoo 17Celine George
In Odoo 17, confirmed and uninvoiced sales orders are now factored into a partner's total receivables. As a result, the credit limit warning system now considers this updated calculation, leading to more accurate and effective credit management.
Front Desk Management in the Odoo 17 ERPCeline George
Front desk officers are responsible for taking care of guests and customers. Their work mainly involves interacting with customers and business partners, either in person or through phone calls.
How to Configure Time Off Types in Odoo 17Celine George
Now we can take look into how to configure time off types in odoo 17 through this slide. Time-off types are used to grant or request different types of leave. Only then the authorities will have a clear view or a clear understanding of what kind of leave the employee is taking.
How to Show Sample Data in Tree and Kanban View in Odoo 17Celine George
In Odoo 17, sample data serves as a valuable resource for users seeking to familiarize themselves with the functionalities and capabilities of the software prior to integrating their own information. In this slide we are going to discuss about how to show sample data to a tree view and a kanban view.
Split Shifts From Gantt View in the Odoo 17Celine George
Odoo allows users to split long shifts into multiple segments directly from the Gantt view.Each segment retains details of the original shift, such as employee assignment, start time, end time, and specific tasks or descriptions.
Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...Murugan Solaiyappan
Title: Relational Database Management System Concepts(RDBMS)
Description:
Welcome to the comprehensive guide on Relational Database Management System (RDBMS) concepts, tailored for final year B.Sc. Computer Science students affiliated with Alagappa University. This document covers fundamental principles and advanced topics in RDBMS, offering a structured approach to understanding databases in the context of modern computing. PDF content is prepared from the text book Learn Oracle 8I by JOSE A RAMALHO.
Key Topics Covered:
Main Topic : DATA INTEGRITY, CREATING AND MAINTAINING A TABLE AND INDEX
Sub-Topic :
Data Integrity,Types of Integrity, Integrity Constraints, Primary Key, Foreign key, unique key, self referential integrity,
creating and maintain a table, Modifying a table, alter a table, Deleting a table
Create an Index, Alter Index, Drop Index, Function based index, obtaining information about index, Difference between ROWID and ROWNUM
Target Audience:
Final year B.Sc. Computer Science students at Alagappa University seeking a solid foundation in RDBMS principles for academic and practical applications.
About the Author:
Dr. S. Murugan is Associate Professor at Alagappa Government Arts College, Karaikudi. With 23 years of teaching experience in the field of Computer Science, Dr. S. Murugan has a passion for simplifying complex concepts in database management.
Disclaimer:
This document is intended for educational purposes only. The content presented here reflects the author’s understanding in the field of RDBMS as of 2024.
Feedback and Contact Information:
Your feedback is valuable! For any queries or suggestions, please contact muruganjit@agacollege.in
2. A large program in c can be divided to many subprogram
The subprogram posses a self contain components and have well define purpose.
The subprogram is called as a function
Basically a job of function is to do something
C program contain at least one function which is main().
Classification of
Function
Library
function
User define
function
- main() -printf()
-scanf()
-pow()
-ceil()
3. It is much easier to write a structured program where a large program can be divided
into a smaller, simpler task.
Allowing the code to be called many times
Easier to read and update
It is easier to debug a structured program where there error is easy to find and fix
4. 1: #include <stdio.h>
2:
3: long cube(long x);
4:
5: long input, answer;
6:
7: int main( void )
8: {
9: printf(“Enter an integer value: ”);
10: scanf(“%d”, &input);
11: answer = cube(input);
12: printf(“nThe cube of %ld is %ld.n”, input,
answer);
13:
14: return 0;
15: }
16:
17: long cube(long x)
18: {
19: long x_cubed;
20:
21: x_cubed = x * x * x;
22: return x_cubed;
23: }
Function names is cube
Variable that are requires is
long
The variable to be passed
on is X(has single
arguments)—value can be
passed to function so it can
perform the specific task. It
is called
Output
Enter an integer
value:4
The cube of 4 is 64.
Return data type
Arguments/formal
parameter
Actual parameters
5. C program doesn't execute the statement in function until the function is called.
When function is called the program can send the function information in the form
of one or more argument.
When the function is used it is referred to as the called function
Functions often use data that is passed to them from the calling function
Data is passed from the calling function to a called function by specifying the
variables in a argument list.
Argument list cannot be used to send data. Its only copy data/value/variable that
pass from the calling function.
The called function then performs its operation using the copies.
6. Provides the compiler with the description of functions that will be used later in the
program
Its define the function before it been used/called
Function prototypes need to be written at the beginning of the program.
The function prototype must have :
A return type indicating the variable that the function will be return
Syntax for Function Prototype
return-type function_name( arg-type name-1,...,arg-type name-n);
Function Prototype Examples
double squared( double number );
void print_report( int report_number );
int get_menu_choice( void);
7. It is the actual function that contains the code that will be execute.
Should be identical to the function prototype.
Syntax of Function Definition
return-type function_name( arg-type name-1,...,arg-type name-n) ---- Function header
{
declarations;
statements;
return(expression);
}
Function Body
8. Function Definition Examples
float conversion (float celsius)
{
float fahrenheit;
fahrenheit = celcius*33.8
return fahrenheit;
}
The function name’s is conversion
This function accepts arguments celcius of the type float. The function return a float
value.
So, when this function is called in the program, it will perform its task which is to convert
fahrenheit by multiply celcius with 33.8 and return the result of the summation.
Note that if the function is returning a value, it needs to use the keyword return.
9. Can be any of C’s data type:
char
int
float
long………
Examples:
int func1(...) /* Returns a type int. */
float func2(...) /* Returns a type float. */
void func3(...) /* Returns nothing. */
10. Function can be divided into 4 categories:
A function with no arguments and no return value
A function with no arguments and a return value
A function with an argument or arguments and returning no value
A function with arguments and returning a values
11. A function with no arguments and no return
value
Called function does not have any arguments
Not able to get any value from the calling function
Not returning any value
There is no data transfer between the calling function and called
function.
#include<stdio.h>
#include<conio.h>
void printline();
void main()
{
printf("Welcome to function in
C");
printline();
printf("Function easy to learn.");
printline();
getch();
}
void printline()
{
int i;
printf("n");
for(i=0;i<30;i++)
{ printf("-"); }
printf("n");
}
12. A function with no arguments and a return value
Does not get any value from the calling function
Can give a return value to calling program
#include <stdio.h>
#include <conio.h>
int send();
void main()
{
int z;
z=send();
printf("nYou entered : %d.",z);
getch();
}
int send()
{
int no1;
printf("Enter a no: ");
scanf("%d",&no1);
return(no1);
}
Enter a no: 46
You entered : 46.
13. A function with an argument or arguments and returning
no value
A function has argument/s
A calling function can pass values to function called , but calling function not
receive any value
Data is transferred from calling function to the called function but no data is
transferred from the called function to the calling function
Generally Output is printed in the Called function
A function that does not return any value cannot be used in an expression it can
be used only as independent statement.
14. #include<stdio.h>
#include<conio.h>
void add(int x, int y);
void main()
{
add(30,15);
add(63,49);
add(952,321);
getch();
}
void add(int x, int y)
{
int result;
result = x+y;
printf("Sum of %d and %d is
%d.nn",x,y,result);
}
15. A function with arguments and returning a values
Argument are passed by calling function to the called function
Called function return value to the calling function
Mostly used in programming because it can two way communication
Data returned by the function can be used later in our program for further
calculation.
16. Result 85.
Result 1273.
#include <stdio.h>
#include <conio.h>
int add(int x,int y);
void main()
{
int z;
z=add(952,321);
printf("Result %d. nn",add(30,55));
printf("Result %d.nn",z);
getch();
}
int add(int x,int y)
{
int result;
result = x + y;
return(result);
}
Send 2 integer value x and y to add()
Function add the two values and send
back the result to the calling function
int is the return type of function
Return statement is a keyword and in
bracket we can give values which we
want to return.
17. Variable that declared occupies a memory according to it size
It has address for the location so it can be referred later by CPU for manipulation
The ‘*’ and ‘&’ Operator
Int x= 10
x
10
76858
Memory location name
Value at memory location
Memory location address
We can use the address which also point the same value.
19. #include <stdio.h>
#include <conio.h>
void main()
{
int i=9;
printf("Value of i : %dn",i);
printf("Address of i %dn", &i);
printf("Value at address of i: %d", *(&i));
getch();
}
* Symbols called the value at the addres
20. #include <stdio.h>
#include <conio.h>
int Value (int x);
int Reference (int *x);
int main()
{
int Batu_Pahat = 2;
int Langkawi = 2;
Value(Batu_Pahat);
Reference(&Langkawi);
printf("Batu_Pahat is number %dn",Batu_Pahat);
printf("Langkawi is number %d",Langkawi);
}
int Value(int x)
{
x = 1;
}
int Reference(int *x)
{
*x = 1;
}
Pass by reference
You pass the variable address
Give the function direct access to the variable
The variable can be modified inside the
21. #include <stdio.h>
#include <conio.h>
void callByValue(int, int);
void callByReference(int *, int *);
int main()
{
int x=10, y =20;
printf("Value of x = %d and y = %d. n",x,y);
printf("nCAll By Value function call...n");
callByValue(x,y);
printf("nValue of x = %d and y = %d.n", x,y);
printf("nCAll By Reference function call...n");
callByReference(&x,&y);
printf("Value of x = %d and y = %d.n", x,y);
getch();
return 0;
}
22. void callByValue(int x, int y)
{
int temp;
temp=x;
x=y;
y=temp;
printf("nValue of x = %d and y = %d inside callByValue function",x,y);
}
void callByReference(int *x, int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}