SlidePlayer

  • My presentations

Auth with social network:

Download presentation

We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!

Presentation is loading. Please wait.

Constants, Variables, and Data Types

Published by Matthew Curran Modified over 10 years ago

Similar presentations

Presentation on theme: "Constants, Variables, and Data Types"— Presentation transcript:

Constants, Variables, and Data Types

Variables in C Amir Haider Lecturer.

powerpoint presentation data types in c

Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.

powerpoint presentation data types in c

Fundamentals of Computer and programming in C

powerpoint presentation data types in c

CSci 1130 Intro to Programming in Java

powerpoint presentation data types in c

Introduction to C Programming

powerpoint presentation data types in c

Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.

powerpoint presentation data types in c

1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.

powerpoint presentation data types in c

CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.

powerpoint presentation data types in c

0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations Imperative Programming, B. Hirsbrunner,

powerpoint presentation data types in c

0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations System-oriented Programming, B. Hirsbrunner,

powerpoint presentation data types in c

Data Types.

powerpoint presentation data types in c

Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.

powerpoint presentation data types in c

Variable & Constants. A variable is a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines.

powerpoint presentation data types in c

Chapter 2: C Fundamentals Dr. Ameer Ali. Overview C Character set Identifiers and Keywords Data Types Constants Variables and Arrays Declarations Expressions.

powerpoint presentation data types in c

A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.

powerpoint presentation data types in c

Input & Output: Console

powerpoint presentation data types in c

The C Character Set: The Characters used to form words, numbers and Expression depends upon the computer on which program runs. Letters. Digits White spaces.

powerpoint presentation data types in c

C Tokens Identifiers Keywords Constants Operators Special symbols.

powerpoint presentation data types in c

Programming I Introduction Introduction The only way to learn a new programming language is by writing programs in it. The first program to.

About project

© 2024 SlidePlayer.com Inc. All rights reserved.

  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Preprocessors
  • C File Handling
  • C Cheatsheet
  • C Interview Questions

Data Types in C

Each variable in C has an associated data type. It specifies the type of data that the variable can store like integer, character, floating, double, etc. Each data type requires different amounts of memory and has some specific operations which can be performed over it. The data type is a collection of data with values having fixed values, meaning as well as its characteristics.

The data types in C can be classified as follows:

Types

Description

Primitive data types are the most basic data types that are used for representing simple values such as integers, float, characters, etc.
The user-defined data types are defined by the user himself.
The data types that are derived from the primitive or built-in datatypes are referred to as Derived Data Types.

Data Types in C

Different data types also have different ranges up to which they can store numbers. These ranges may vary from compiler to compiler. Below is a list of ranges along with the memory requirement and format specifiers on the 32-bit GCC compiler .

Data Type 
 
Size (bytes) 
 
Range
 
Format Specifier 
 


 
-32,768 to 32,767 
 
%hd 
 


 
0 to 65,535 
 
%hu 
 


 
0 to 4,294,967,295 
 
%u 
 


 
-2,147,483,648 to 2,147,483,647 
 
%d 
 


 
-2,147,483,648 to 2,147,483,647 
 
%ld 
 


 
0 to 4,294,967,295 
 
%lu 
 


 
-(2^63) to (2^63)-1 
 
%lld 
 


 
0 to 18,446,744,073,709,551,615 
 
%llu 
 


 
-128 to 127 
 
%c 
 


 
0 to 255 
 
%c 
 


 
1.2E-38 to 3.4E+38 %f 
 


 
1.7E-308 to 1.7E+308 %lf 
 

16 
 
3.4E-4932 to 1.1E+4932 %Lf 
 
Note: The l ong, short, signed and unsigned are datatype modifier that can be used with some primitive data types to change the size or length of the datatype.

The following are some main primitive data types in C:

Integer Data Type

The integer datatype in C is used to store the integer numbers(any number including positive, negative and zero without decimal part). Octal values, hexadecimal values, and decimal values can be stored in int data type in C. 

  • Range:  -2,147,483,648 to 2,147,483,647
  • Size: 4 bytes
  • Format Specifier: %d

Syntax of Integer

We use int keyword to declare the integer variable:

The integer data type can also be used as

  • unsigned int: Unsigned int data type in C is used to store the data values from zero to positive numbers but it can’t store negative values like signed int.
  • short int: It is lesser in size than the int by 2 bytes so can only store values from -32,768 to 32,767.
  • long int: Larger version of the int datatype so can store values greater than int.
  • unsigned short int: Similar in relationship with short int as unsigned int with int.
Note: The size of an integer data type is compiler-dependent. We can use sizeof operator to check the actual size of any data type.

Example of int

Character Data Type

Character data type allows its variable to store only a single character. The size of the character is 1 byte. It is the most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers.

  • Range: (-128 to 127) or (0 to 255)
  • Size: 1 byte
  • Format Specifier: %c

Syntax of char

The char keyword is used to declare the variable of character type:

Example of char

Float Data Type

In C programming float data type is used to store floating-point values. Float in C is used to store decimal and exponential values. It is used to store decimal numbers (numbers with floating point values) with single precision.

  • Range: 1.2E-38 to 3.4E+38
  • Format Specifier: %f

Syntax of float

The float keyword is used to declare the variable as a floating point:

Example of Float

Double Data Type

A Double data type in C is used to store decimal numbers (numbers with floating point values) with double precision. It is used to define numeric values which hold numbers with decimal values in C.

The double data type is basically a precision sort of data type that is capable of holding 64 bits of decimal numbers or floating points. Since double has more precision as compared to that float then it is much more obvious that it occupies twice the memory occupied by the floating-point type. It can easily accommodate about 16 to 17 digits after or before a decimal point.

  • Range: 1.7E-308 to 1.7E+308
  • Size: 8 bytes
  • Format Specifier: %lf

Syntax of Double

The variable can be declared as double precision floating point using the double keyword:

Example of Double

Void Data Type

The void data type in C is used to specify that no value is present. It does not provide a result value to its caller. It has no values and no operations. It is used to represent nothing. Void is used in multiple ways as function return type, function arguments as void, and pointers to void .

Example of Void

Size of Data Types in C

The size of the data types in C is dependent on the size of the architecture, so we cannot define the universal size of the data types. For that, the C language provides the sizeof() operator to check the size of the data types.

To check your knowledge of data types in C, go through the Quiz on Data Types .

Please Login to comment...

Similar reads.

  • C-Data Types
  • 105 Funny Things to Do to Make Someone Laugh
  • Best PS5 SSDs in 2024: Top Picks for Expanding Your Storage
  • Best Nintendo Switch Controllers in 2024
  • Xbox Game Pass Ultimate: Features, Benefits, and Pricing in 2024
  • #geekstreak2024 – 21 Days POTD Challenge Powered By Deutsche Bank

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

Newly Launched - AI Presentation Maker

SlideTeam

AI PPT Maker

Powerpoint Templates

Icon Bundle

Kpi Dashboard

Professional

Business Plans

Swot Analysis

Gantt Chart

Business Proposal

Marketing Plan

Project Management

Business Case

Business Model

Cyber Security

Business PPT

Digital Marketing

Digital Transformation

Human Resources

Product Management

Artificial Intelligence

Company Profile

Acknowledgement PPT

PPT Presentation

Reports Brochures

One Page Pitch

Interview PPT

All Categories

Top 10 Information Classification PowerPoint Presentation Templates in 2024

Introducing our fully editable and customizable PowerPoint presentation on Information Classification, designed to empower organizations in effectively managing their data. This presentation serves as a comprehensive guide to understanding the importance of categorizing information based on its sensitivity and value. With a user-friendly layout and visually engaging graphics, it allows teams to easily illustrate complex concepts such as data classification levels, security protocols, and compliance requirements. Use cases for this presentation are vast and diverse. Businesses can utilize it during training sessions to educate employees about the significance of proper information handling and the potential risks of data breaches. IT departments can leverage it to communicate classification frameworks that align with regulatory standards, ensuring that sensitive information is adequately protected. Additionally, the presentation can be adapted for strategic meetings to discuss data management policies, fostering a culture of security awareness within the organization. Whether for internal training, stakeholder presentations, or compliance workshops, our Information Classification PowerPoint is an essential tool for promoting data security and informed decision-making in todays information-driven landscape. Tailor it to fit your specific needs and enhance your team's understanding of effective information management.

powerpoint presentation data types in c

Data classification example powerpoint guide

Presenting data classification example PowerPoint guide slideshow which is 100% editable. This PPT template is crafted with attractive display and unique components. This PPT slide is easy to customize and enables you to personalize it as per your own criteria. The presentation slide is fully compatible with Google slides, multiple format and software options. In case of any assistance, kindly take instructions from our presentation design services and it is easy to download in a very short span of time. The images, layouts, designs are of high quality and ensures quality in widescreen.

Use the data classification example PowerPoint guide slideshow in the field of data management, data classification which is an effective tool that can be used for the categorization of data and further enables / helps organizations to effectively answer the questions such as; what data types are available, where are certain data located, what access levels are implemented, what protection level is implemented and does it adhere to compliance regulations? Implement the information incorporated in the information management layout PPT slide as it works as a bridge between IT professionals and process or application owners. The template is a platform which can be used to inform about the data value and management (usually application owners) to the viewers / team members to make them understand better that which part of the data centre needs to be invested in to keep operations running effectively. Avail the benefits of the PowerPoint shape and make calculations in risk management, legal discovery and compliance with government regulations. Make a statement with your statements. Data Classification Example Powerpoint Guide can help your presentations say more.

  • data management
  • Data Classification
  • Information Lifecycle Management

powerpoint presentation data types in c

Structured and unstructured classification of big data

Presenting this set of slides with name Structured And Unstructured Classification Of Big Data. The topics discussed in these slides are Structured, Unstructured, Classification, Big Data. This is a completely editable PowerPoint presentation and is available for immediate download. Download now and impress your audience.

Generate goodwill with our Structured And Unstructured Classification Of Big Data. Feelings will build in your favor.

  • Unstructured
  • classification

powerpoint presentation data types in c

Data classification types ppt icon

Presenting data classification types PPT icon PPT slide. PPT has 100 percent editable content. Ease of addition and deletion of content for the desired level of customization. You may even personalize the presentation with your company specific name and logo. Compatible with multiple numbers of software options available both online and offline. PPT is compatible with numerous format options like JPEG, JPG and PDF. Picture quality does not pixelate when projected on a wide screen. Special guidelines for executing the changes are provided as assistance. Such presentation is used by a team of marketing professionals, entrepreneurs, scholars, and teachers.

In any corporate organization, there is a presence of a plethora of data and information which vary in level of their privacy and significance. On these two and multiple other parameters, the data section of the company can be classified as public, internal use, confidential and regulatory handling. In the given data management PPT model, these multiple categories of data have been provided with a unique color code and also PPT icon as an exclusive identity and classification essence of each. This categorization of data PPT PowerPoint template can be used by professionals belonging to any organization irrespective of the nature of business of that corporation. Data management PPT presentation is an extensive presentation comprising of multiple slides where this one slide of data category can add its value and raise the bar of presentation. It's easy to present as well as easy to comprehend. Elicit the acknowledgement you desire with our Data Classification Types Ppt Icon. You will have a beneficial interaction.

powerpoint presentation data types in c

Information security classification ppt powerpoint presentation inspiration picture cpb

Presenting Information Security Classification Ppt Powerpoint Presentation Inspiration Picture Cpb slide which is completely adaptable. The graphics in this PowerPoint slide showcase five stages that will help you succinctly convey the information. In addition, you can alternate the color, font size, font type, and shapes of this PPT layout according to your content. This PPT presentation can be accessed with Google Slides and is available in both standard screen and widescreen aspect ratios. It is also a useful set to elucidate topics like Information Security Classification. This well structured design can be downloaded in different formats like PDF, JPG, and PNG. So, without any delay, click on the download button now.

Our Information Security Classification Ppt Powerpoint Presentation Inspiration Picture Cpb are topically designed to provide an attractive backdrop to any subject. Use them to look like a presentation pro.

  • Information Security Classification

powerpoint presentation data types in c

Data Classification Policy Overview And Approaches Information Technology Policy

This slide represents the data classification policy overview and approaches. Approaches include highly restricted, restricted, and internal use and types of data each approach will include. Introducing Data Classification Policy Overview And Approaches Information Technology Policy to increase your presentation threshold. Encompassed with three stages, this template is a great option to educate and entice your audience. Dispence information on Highly Restricted, Restricted, Internal Use, using this template. Grab it now to reap its full benefits.

This slide represents the data classification policy overview and approaches. Approaches include highly restricted, restricted, and internal use and types of data each approach will include.

  • Highly Restricted
  • Internal Use

powerpoint presentation data types in c

Classification Of Devops Key Training Concepts

This slide showcases the explanation of devops major training concepts. It include details such as continuous integration, infrastructure as code, etc. Presenting our set of slides with Classification Of Devops Key Training Concepts This exhibits information on three stages of the process. This is an easy to edit and innovatively designed PowerPoint template. So download immediately and highlight information on Continuous Integration, Infrastructure As Code, Monitoring And Logging

This slide showcases the explanation of devops major training concepts. It include details such as continuous integration, infrastructure as code, etc.

  • Continuous Integration
  • Infrastructure As Code
  • Monitoring And Logging

powerpoint presentation data types in c

Request Form For Project Information And Classification

This slide showcases project request form to document and communicate key information to target audience. It further includes details about title, division, objectives, current process, etc. Presenting our well structured Request Form For Project Information And Classification. The topics discussed in this slide are Request Information, Project Information, Project Classication. This is an instantly available PowerPoint presentation that can be edited conveniently. Download it right away and captivate your audience.

This slide showcases project request form to document and communicate key information to target audience. It further includes details about title, division, objectives, current process, etc.

  • Request Information
  • Project Information
  • Project Classication

powerpoint presentation data types in c

Classification Of Corporate Internal And External Stakeholders

This slide highlights classification of stakeholders to group them according to category, level of impact, roles and interests. Its key stakeholders are c- suite executives, managers, accounts, procurement, employees, HR, IT and government bodies. Presenting our set of slides with name Classification Of Corporate Internal And External Stakeholders. This exhibits information on eight stages of the process. This is an easy-to-edit and innovatively designed PowerPoint template. So download immediately and highlight information on Employees, Account, Managers, Procurement, HR.

This slide highlights classification of stakeholders to group them according to category, level of impact, roles and interests. Its key stakeholders are c suite executives, managers, accounts, procurement, employees, HR, IT and government bodies.

  • procurement

powerpoint presentation data types in c

Information Data Classification Ppt Powerpoint Presentation Slides Infographic Template Cpb

Presenting Information Data Classification Ppt Powerpoint Presentation Slides Infographic Template Cpb slide which is completely adaptable. The graphics in this PowerPoint slide showcase four stages that will help you succinctly convey the information. In addition, you can alternate the color, font size, font type, and shapes of this PPT layout according to your content. This PPT presentation can be accessed with Google Slides and is available in both standard screen and widescreen aspect ratios. It is also a useful set to elucidate topics like Information Data Classification. This well structured design can be downloaded in different formats like PDF, JPG, and PNG. So, without any delay, click on the download button now.

Our Information Data Classification Ppt Powerpoint Presentation Slides Infographic Template Cpb are topically designed to provide an attractive backdrop to any subject. Use them to look like a presentation pro.

  • Information Data Classification

powerpoint presentation data types in c

Information system classification ppt powerpoint presentation ideas background images cpb

Presenting our Information System Classification Ppt Powerpoint Presentation Ideas Background Images Cpb PowerPoint template design. This PowerPoint slide showcases three stages. It is useful to share insightful information on Information System Classification This PPT slide can be easily accessed in standard screen and widescreen aspect ratios. It is also available in various formats like PDF, PNG, and JPG. Not only this, the PowerPoint slideshow is completely editable and you can effortlessly modify the font size, font type, and shapes according to your wish. Our PPT layout is compatible with Google Slides as well, so download and edit it as per your knowledge.

Our Information System Classification Ppt Powerpoint Presentation Ideas Background Images Cpb are topically designed to provide an attractive backdrop to any subject. Use them to look like a presentation pro.

  • Information System Classification

Google Reviews

ics103 programming in c lecture 9 functions i

Functions in C Programming: Types, Arguments, and Reusability

Nov 29, 2023

250 likes | 292 Views

This lecture discusses the different types of functions in C programming, including void functions with arguments, formal parameters and actual arguments, and the reusability of functions. It also covers modular programming and the advantages of using function subprograms.

Share Presentation

  • c programming
  • void functions
  • formal parameters
  • actual arguments
  • modular programming
  • reusability

meyerjohn

Presentation Transcript

ICS103 Programming in CLecture 9: Functions I

Outline • Review about Functions • Types of Functions • void Functions with Arguments • Actual Arguments & Formal Parameters • Writing Modular programs using functions • Functions with Input Argument and a Single Result • Re-usability of Functions • Logical Functions • Functions with Multiple Arguments • Argument List Correspondence • The Function Data Area • Testing Functions Using Drivers • Advantages of Using Function Subprograms • Procedural Abstraction • Reuse of Functions.

Review about Functions • In chapter 3, we introduced functions as program modules that perform some operations that contribute towards solving the problem that a C program is designed to solve. • We learnt how to use functions from the standard C library such as those in <math.h> and <stdio.h>. • We also learnt the steps involved in defining our own (user-defined) functions, namely: • Declare the function prototype before the main function • Define the detail implementation of the function after the main function • Call the function from the main function where its operation is required • However, we learnt to write only the simplest type of functions – those that take no argument and return nothing. • In this Lecture, we shall learn how to write functions that take arguments, those that return a result and those that do both.

Types of Functions • We use function arguments to communicate with the function. There are two types of function arguments: • Input arguments – ones that are used to pass information from the caller (such as main function) to the function. • Output arguments – ones that return results to the caller from the function. [we shall learn about these in the next lecture] • Types of Functions • No input arguments, no value returned – void functions without arguments [already discussed in chapter 3] • Input arguments, no value returned - void functions with arguments. • Input arguments, single value returned. • Input arguments, multiple value returned [next lecture]

void Functions with Input Arguments … • A function may take one or more arguments as input but returns no result. • Such functions should be declared as void, but each argument should be declared in the bracket following the function name • An argument is declared in the same way as variables (its type followed by the name of the argument). Example: void print_rboxed(double rnum); • If there are more than one argument, they should be separated by comma. Example: void draw_rectangle(int length, int width); • The following function example displays its argument value in a rectangular box.

void Functions with Input Arguments… /* Uses the print_rboxed function to display a double argument */ #include <stdio.h> void print_rboxed(double rnum); //prototype for the function int main(void) { double x; printf("Enter a double value > "); scanf("%lf", &x); print_rboxed(x); //function call return 0; } /* Displays a real number in a box. */ void print_rboxed(double rnum) { printf("***********\n"); printf("* *\n"); printf("* %7.2f *\n", rnum); printf("* *\n"); printf("***********\n"); }

Actual Arguments & Formal Parameters • Actual argument: an expression used inside the parentheses of a function call. • Formal parameter: An identifier that represents a corresponding actual argument in a function definition. • Actual argument can be any expression that evaluates to a value expected by the function: x, 125.5, x+y, etc. • When the function call is encountered at run-time, the expression for the actual argument is first evaluated, the resulting value is assigned to the formal parameter, then the function is executed. • Arguments make functions more versatile because they enable a function to manipulate different data each time it is called.

Writing Modular programs using functions • Suppose we wish to write a program that draws a rectangle similar to the following given the length and width. • An algorithm for the solution could be: • Draw a solid line by printing ‘*’ width times • Draw a hollow line (‘*’, width-2 spaces and ‘*’) length – 2 times • Draw a solid line by printing * width times • It is possible to write a very long main method to implement the above algorithm. • However, this will involve many repetitions and the code will be difficult to re-use in another application. • A better approach is to implement the different components of the solution as functions – this will result in a modular program and re-usable functions. • The above algorithm could involve three functions, namely, draw_rectangle, draw_solid_line and draw_hollow_line

Writing Modular programs using functions … void draw_hollow_line(int size) { int i; printf("*"); if (size > 2) { for (i=1; i<= size-2; i++) printf(" "); } printf("*\n"); } void draw_rectangle(int len, int wide) { int i; draw_solid_line(wide); if (len > 2) { for (i=1; i<=len - 2; i++) draw_hollow_line(wide); } draw_solid_line(wide); } //draws a rectangle using functions #include <stdio.h> void draw_solid_line(int size); void draw_hollow_line(int size); void draw_rectangle(int len, int wide); int main(void) { int length, width; printf("Enter length and width of rectangle >"); scanf("%d%d", &length, &width); draw_rectangle(length, width); system("pause"); return 0; } void draw_solid_line(int size) { int i; for (i=1; i<=size; i++) printf("*"); printf("\n"); }

Functions with Input Argument and a Single Result • By far, the must common types of functions in C are those that takes one or more arguments and return a single result. • For example, virtually all the functions in the <math.h> library, sqrt, log, abs, sin, cos, etc. are in this category. • Unlike void functions, for which the function call is a statement on its own, functions that return a single result are often called as part of another expression. • To declare these types of function, instead of void, the function name is preceded by the type of result the function returns (int, double, char, etc.).

Functions with Input Argument and a Single Result… • Functions that return a single result must have at least one return statement that returns the result to the calling function. /* Computes n! for n greater than or equal to zero */ int factorial (int n) { int i, /* local variables */ product = 1; /* Computes the product n x (n-1) x (n-2) x ... x 2 x 1 */ for (i = n; i > 1; --i) { product *= i; } /* Returns function result */ return product; }

The complete factorial example /* Computes n! for n greater than or equal to zero */ int factorial(int n) { int i, /* local variables */ product = 1; /* Computes the product n x (n-1) x (n-2) x ... x 2 x 1 */ for (i = n; i > 1; --i) { product *= i; } /* Returns function result */ return (product); } /* Computes the factorial of a number */ #include <stdio.h> int factorial(int n); /* shows how to call a user-define function */ int main(void) { int num, fact; printf("Enter an integer between 0 and 10> "); scanf("%d", &num); if (num < 0) { printf("Factorial not defined for negative numbers\n"); } else if (num <= 7) { fact = factorial(num); printf("The factorial of %d is %d\n", num, fact); } else { printf("Number out of range: %d\n", num); } system("pause"); return (0); }

Re-usability of Functions • One important advantage of using functions is that they are reusable. • If we need to write another program that uses the same function, we do not need to re-write the function – just use the one we had before. • For example, suppose we wish to write a program that computes how many different ways we can choose r items from a total of n items. • E.g. How many ways we can choose 2 letters from 3 letters (A, B, C). • From probability theory, this number is given by the combination formula: • In our example, we have:

Re-usability of Functions … /* Uses the factorial function to computes the number of combinations of n items taken r at a time. It assumes n >= r */ int combinations(int n, int r) { return factorial(n) / (factorial(r) * factorial(n-r)); } /* Computes n! for n greater than or equal to zero */ int factorial(int n) { int i, /* local variables */ product = 1; for (i = n; i > 1; --i) { product *= i; } /* Returns function result */ return (product); } /* Uses the combination functions to computes the number of combinations of n items taken r at a time */ #include <stdio.h> int factorial(int n); int combinations(int n, int r); int main(void) { int n, r, c; printf("Enter total number of components> "); scanf("%d", &n); printf("Enter number of components selected> "); scanf("%d", &r); if (r <= n) { c = combinations(n, r); printf("The number of combinations is %d\n", c); } else { printf("Components selected cannot exceed total number\n"); } system("pause"); return (0); }

Logical functions • As we have observed by now, C uses integers to represent logical values. • Thus, a function that returns a logical result should be declared as type int. In the implementation, the function return 0 for false or any other value for true. • Example, the following is a logical function that checks if its integer argument is even or not. One important advantage of using functions is that they are reusable. • The function is used as follows: /* Indicates whether or not num is even. Returns 1 if it is, 0 if not */ int even(int num) { int ans; ans = ((num % 2) == 0); return (ans); } if (even(n)) even_nums++; else odd_nums++;

Functions with Multiple Arguments • As we saw with the functions draw_rectangle (int len, int wide|) and combination (int n, int r), a function can have multiple arguments. • Below is another function that multiplies its first argument by 10 raised to the power of its second argument. • Function call scale(2.5, 2)returns the value 250.0 /* Multiplies its first argument by the power of 10 specified by its second argument. */ double scale(double x, int n) { double scale_factor; /* local variable */ scale_factor = pow(10, n); return (x * scale_factor); }

Argument List Correspondence • When using multiple-argument functions, the number of actual argument used in a function call must be the same as the number of formal parameters listed in the function prototype. • The order of the actual arguments used in the function call must correspond to the order of the parameters listed in the function prototype. • Each actual argument must be of a data type that can be assigned to the corresponding formal parameter with no unexpected loss of information.

Testing Function scale /* Tests function scale */ #include <math.h> #include <stdio.h> double scale(double x, int n); int main(void) { double num_1; int num_2; /* Get values for num 1 and num 2 */ printf("Enter a real number> "); scanf("%lf", &num_1); printf("Enter an integer> "); scanf("%d", &num_2); /* Call scale and display result. */ printf("Result of call to function scale is %.3f\n", scale(num_1, num_2)); system ("pause"); return (0);} double scale(double x, int n) { double scale_factor; scale_factor = pow(10, n); return (x * scale_factor); }

The Function Data Area • Each time a function call is executed, an area of memory is allocated for storage of that function’s data. • Included in the function data area are storage cells for its formal parameters and any local variables that may be declared in the function. • Local Variables: variable declarations within a function body. • Can only be used from within the function they are declared in – no other function can see them • These variables are created only when the function has been activated and become undefined after the call. • The function data area is always lost when the function terminates. • It is recreated empty when the function is called again. • So if you set a local variable value, that value will be reset again next time the function is called.

Data Areas After Call scale(num_1, num_2);

Testing Functions Using Drivers • A function is an independent program module • As such, it can be tested separately from the program that uses it. • To run such a test, you should write a short piece of code called driver that defines the function arguments, calls the functions, and displays the value returned. • As long as you do not change the interface, your function can be reused.

Why do we use Functions? • There are two major reasons: • A large problem can be solved easily by breaking it up into several small problems and giving the responsibility of a set of functions to a specific programmer. • It is easer to write two 10 line functions than one 20 line function and two smaller functions will be easier to read than one long one. • They can simplify programming tasks because existing functions can be reused as the building blocks for new programs. • Really useful functions can be bundled into libraries.

Procedural Abstraction • Procedural Abstraction – A programming technique in which a main function consists of a sequence of function calls and each function is implemented separately. • All of the details of the implementation to a particular subproblem is placed in a separate function. • The main functions become a more abstract outline of what the program does. • When you begin writing your program, just write out your algorithm in your main function. • Take each step of the algorithm and write a function that performs it for you. • Focusing on one function at a time is much easier than trying to write the complete program at once.

Reuse of Function Subprograms • Functions can be executed more than once in a program. • Reduces the overall length of the program and the chance of error. • Once you have written and tested a function, you can use it in other programs or functions.

Common Programming Errors • Remember to use a #include preprocessor directives for every standard library from which you are using functions. • Place prototypes for your own function subprogram in the source file preceding the main function; place the actual function definitions after the main function. • The acronym NOT summarizes the requirements for argument list correspondence. • Provide the required Number of arguments • Make sure the Order of arguments is correct • Make sure each argument is the correct Type or that conversion to the correct type will lose no information. • Include a statement of purpose on every function you write. • Also be careful in using functions that are undefined on some range of values.

  • More by User

GC16/3011 Functional Programming Lecture 9 Higher Order Functions

GC16/3011 Functional Programming Lecture 9 Higher Order Functions

GC16/3011 Functional Programming Lecture 9 Higher Order Functions. Contents. Higher Order Functions Definition Example: composition Combinators Definition Example: S, K, I Capturing common forms of recursion on lists Examples: map and filter. Higher Order Functions. Definition:

187 views • 18 slides

COMPSCI 101 Principles of Programming

COMPSCI 101 Principles of Programming

COMPSCI 101 Principles of Programming. Lecture 06 – Testing Functions. Learning outcomes. At the end of this lecture, students should be able to: Divide a problem up into different tasks Write a function to perform each task Create a solution to the problem using multiple functions. Recap.

263 views • 11 slides

C++ Programming Lecture 14

C++ Programming Lecture 14

C++ Programming Lecture 14. Wei Liu ( 刘威 ) Dept. of Electronics and Information Eng. Huazhong University of Science and Technology Feb. 2014. Lecture 14. Chapter 16. Introduction to Class and Object 16.1 Introduction 16.2 Classes, Objects, Member Functions and Data Members

736 views • 48 slides

Lecture 2: Programming Review and Introduction to Software Design

Lecture 2: Programming Review and Introduction to Software Design

SWE 316: Software Design &amp; Architecture. Lecture 2: Programming Review and Introduction to Software Design. To review programming conventions To review the good habit of writing functions To define goals of software design. Documenting Functions. Describing Functions. Software Design.

586 views • 27 slides

CS1022 Computer Programming &amp; Principles

CS1022 Computer Programming &amp; Principles

CS1022 Computer Programming &amp; Principles. Lecture 5.2 Functions (2). Plan of lecture. Inverse functions Composition of functions Pigeonhole principle Fundamentals of functional programming. Inverse functions (1).

336 views • 24 slides

LECTURE 11: Dynamic programming - II -

LECTURE 11: Dynamic programming - II -

LECTURE 11: Dynamic programming - II -. Outline. What do we know about dynamic programming ? Application: discrete knapsack Memory functions (memoization) Application: optimal multiplication of matrices Application: transitive closure of a binary relation.

582 views • 42 slides

ITEC 109

ITEC 109. Multimedia Lecture Lecture 23. Review. Lists / Arrays. Objectives. Learned basics of programming languages What can you do with them? Is programming really about writing functions? Learn how to do image manipulation. Source. Background. Get in the game. Tools. Pixels: Red

339 views • 20 slides

CSE 341 : Programming Languages Lecture 2 Functions, Pairs, Lists

CSE 341 : Programming Languages Lecture 2 Functions, Pairs, Lists

CSE 341 : Programming Languages Lecture 2 Functions, Pairs, Lists. Zach Tatlock Spring 2014. What is an ML program?. A sequence of bindings from names to expressions. Build powerful progs by composing simple constructs. Build rich exprs from simple exprs

361 views • 28 slides

CSE 341 : Programming Languages Lecture 8 First Class Functions

CSE 341 : Programming Languages Lecture 8 First Class Functions

CSE 341 : Programming Languages Lecture 8 First Class Functions. Zach Tatlock Spring 2014. What is functional programming?. “ Functional programming ” can mean a few different things: Avoiding mutation in most/all cases (done and ongoing) Using functions as values (this unit) …

329 views • 19 slides

Lecture 04 Functions - I

Lecture 04 Functions - I

Wed July 8, 2002. Lecture 04 Functions - I. METU Dept. of Computer Eng. Summer 2002 Ceng230 - Section 01 Introduction To C Programming by Ahmet Sacan. re-glance @ TOC. Variables, Data Types Conditionals: if, ?, switch Loops: for, while, do-while Functions Arrays Strings.

316 views • 23 slides

Functional Programming Lecture 12 - more higher order functions

Functional Programming Lecture 12 - more higher order functions

Functional Programming Lecture 12 - more higher order functions. Recursion over two arguments. The function zip “zips” together two lists, to produce a new list of pairs. zip :: [a] -&gt; [b] -&gt; [(a,b)] zip (x:xs) (y:ys) = (x,y) : zip xs ys zip _ _ = [] or

248 views • 8 slides

COMP313A Programming Languages

COMP313A Programming Languages

COMP313A Programming Languages. Functional Programming (5). Lecture Outline. Higher order functions Functions as arguments Some recapping and exercises Some more functions as data and results. Expressions Defining Functions. addnum :: Int -&gt; (Int -&gt; Int) addnum n = addN

371 views • 24 slides

Functional programming

Functional programming

Functional programming. Functional style makes heavy use of functions as values Hence, functional languages provide powerful constructs for manipulating functions. Higher-order functions. Functions that operate on functions

244 views • 14 slides

System Programming in C

System Programming in C

System Programming in C. Lecture 5. Lecture summary. Binary file I/O String I/O &amp; functions Const qualifier Typedefs Scooping. Binary File I/O. The main functions for binary file I/O are fread, fwrite, fopen, fclose: size_t fread(void *ptr, size_t size, size_t nobj, FILE *stream)

399 views • 28 slides

ICS103 Programming in C Lecture 11: Recursive Functions

ICS103 Programming in C Lecture 11: Recursive Functions

ICS103 Programming in C Lecture 11: Recursive Functions. Outline. Introducing Recursive Functions Format of recursive Functions Tracing Recursive Functions Examples Tracing using Recursive Trees. 1, n = 0. n! =. n (n-1)! , n&gt;1. Introducing Recursive Functions.

643 views • 16 slides

ICS103 Programming in C Lecture 8: Data Files

ICS103 Programming in C Lecture 8: Data Files

ICS103 Programming in C Lecture 8: Data Files. Outline. Why data files? Declaring FILE pointer variables Opening data files for input/output Scanning from and printing to data files Closing input and output files Echo Prints vs. Prompts Handling File not found error EOF-controlled Loops.

266 views • 15 slides

Programming in C++

Programming in C++

Andreas Savva. Programming in C++. Lecture Notes 9 Functions (Returning Values). f(2) = f(-2) = f(4) =. f(2,3) = f(-2,-3) =. Functions in Mathematics. f(x) = x 2. 4 4 16. Parameters. f(x,y) = x 2 +y. 7 1. f = 3. Function. None or many input parameters. Exactly one

423 views • 27 slides

ICS103 Programming in C Lecture 12: Arrays I

ICS103 Programming in C Lecture 12: Arrays I

ICS103 Programming in C Lecture 12: Arrays I. Outline. What is an Array? Declaring Arrays Visual representation of an Array Array Initialization Array Subscripts Accessing Array elements Examples. What is an Array?. Scalar data types use a single memory cell to store a single value.

259 views • 14 slides

ICS103 Programming in C Lecture 6: Selection Structures

ICS103 Programming in C Lecture 6: Selection Structures

ICS103 Programming in C Lecture 6: Selection Structures. Outline. Control Structures Conditions Relational Operators Logical Operators if statements Two-Alternatives One-Alternative Nested If Statements switch Statement. C. N. Y. Y. C. N. Control Structures.

642 views • 42 slides

CSC 1401 S1 Computer Programming I

CSC 1401 S1 Computer Programming I

CSC 1401 S1 Computer Programming I. Hamid Harroud School of Science and Engineering, Akhawayn University [email protected] http://www.aui.ma/~H.Harroud/CSC1401 Spring 2009. Top-Down Design with Functions: Modular Programming. Lecture 6. Lecture 1: Introduction. Objectives.

647 views • 43 slides

Audio Engine Programming

Audio Engine Programming

Audio Engine Programming. Lecture 4 Functions, Arrays and Structures in C++. Introduction. Last week we introduced the C++ language similar to Java different methods for I/O Class construction This lecture we will Introduce Graphics programming using OpenGL and GLUT

670 views • 54 slides

ICS103 Programming in C Ch5: Repetition and Loop Statements

ICS103 Programming in C Ch5: Repetition and Loop Statements

ICS103 Programming in C Ch5: Repetition and Loop Statements. Objectives. Repetition in Programs Counting Loops Using while statement Compound assignment operators Using for statement Increment and Decrement Operators Conditional Loops sentinel-Controlled loops Nested loop

516 views • 32 slides

IMAGES

  1. PPT

    powerpoint presentation data types in c

  2. PPT

    powerpoint presentation data types in c

  3. PPT

    powerpoint presentation data types in c

  4. Data Types in C

    powerpoint presentation data types in c

  5. PPT

    powerpoint presentation data types in c

  6. PPT

    powerpoint presentation data types in c

VIDEO

  1. How to Visualise Data

  2. Our Presentation Types

  3. Beautiful Presentation Slide Design for Business Performance KPI Reporting in PowerPoint

  4. BEST PowerPoint Shortcut 🔥

  5. Very informative #shorts #powerpoint #graph #socialanxiety #happynewyear

  6. How to Protect PowerPoint Presentation Using the .NET PowerPoint Library

COMMENTS

  1. Data Types in C

    Data Types in C.pptx - Free download as Powerpoint Presentation (.ppt / .pptx), PDF File (.pdf), Text File (.txt) or view presentation slides online. The document discusses the different data types in C programming language. It describes the primary data types like integer, real, character, and void. It also discusses derived data types like arrays and pointers.

  2. PPT

    Presentation Transcript. Derived Data Types • Array - a finite sequence (or table) of variables of the same data type • String - an array of character variables • Structure - a collection of related variables of the same and/or different data types. The structure is called a record and the variables in the record are called members ...

  3. PPT

    Primitive datatypes are of the following types: • Integer • Character • Boolean • Floating Point • Double Floating Point • Void or Valueless • Wide Character The sizeof () operator is used to find out the number of bytes occupied by the datatype in the memory. This code demonstrates the use to sizeof operator to find the memory ...

  4. Data Types in C

    Data Types in C ppt - Free download as Powerpoint Presentation (.ppt / .pptx), PDF File (.pdf), Text File (.txt) or view presentation slides online. This document summarizes the primary data types in C programming. It discusses the integer, character, floating-point, double, and void data types. For each data type, it provides the range, size, and format specifier.

  5. PDF DATA TYPES AND EXPRESSIONS

    Expression evaluation. An assignment expression evaluates to a value same as any other expression Value of an assignment expression is the value assigned to the l-value Example: value of. a = 3 is 3. b = 2*4 - 6 is 2. n = 2*u + 3*v - w is whatever the arithmetic expression 2*u + 3*v - w evaluates to given the current values stored in ...

  6. Constants, Variables, and Data Types

    Download ppt "Constants, Variables, and Data Types". Constants, Variables, and Data Types Like any other language, C has its own vocabulary and grammar. In this chapter, we will discuss the concepts of constants and variables and their types as they relate to C programming language.

  7. PPT Data Types

    Almost all programming languages provide a set of primitive data types. primitive data types are those not defined in terms of other data types. some primitive data types are implemented directly in hardware (integers, floating point, etc) while others require some non-hardware support for their implementation such as arrays. Data Types.

  8. Data Types in C

    int var_name;. The integer data type can also be used as. unsigned int: Unsigned int data type in C is used to store the data values from zero to positive numbers but it can't store negative values like signed int. short int: It is lesser in size than the int by 2 bytes so can only store values from -32,768 to 32,767. long int: Larger version of the int datatype so can store values greater ...

  9. PPT PowerPoint Presentation

    C++ guarantees a char is one byte in size Sizes of other types are platform dependent Can determine using sizeof() , <climits> INT_MAX float, double (floating point arithmetic) More expensive in space and time Useful when you need to describe continuous quantities bool type Logic type, takes on values true, false Built-In (a.k.a. Native) Types ...

  10. PDF C programming ppt slides, PDF on arrays

    Compared to the basic data type (int, float) it is an aggregate or derived data type. All the elements of an array occupy a set of contiguous memory locations. Why need to use array type? Consider the following issue: "We have a list of 1000 students' marks of an integer type. If using the basic data type

  11. Data Types in C PowerPoint Presentation, free download

    Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

  12. PPT

    C data types and declarations (Reek, Ch. 3) CS 3090: Safety Critical Programming in C. Four basic data types • Integer: char, short int, int, long int, enum • Floating-point: float, double, long double • Pointer • Aggregate:struct, union • Reek categorizes arrays as "aggregate" types - fair enough, but as we've seen, arrays ...

  13. PPT On Variables And Data Types In Programming Lang

    Data Types-I Different types of data are stored in variables. Some examples are: Numbers Whole numbers. For example, 10 or 178993455 Real numbers. For example, 15.22 or 15463452.25 Positive numbers Negative numbers Names. For example, John Logical values. For example, Y or N Elementary Programming with C/Session 2/ 10 of 22. PPT slide on PPT On ...

  14. PPT

    Presentation Transcript. Data types in C • Primitive data types • int, float, double, char • Aggregate data types • Arrays come under this category • Arrays can contain collection of int or float or char or double data • User defined data types • Structures and enum fall under this category. Variable names- Rules • Should not be ...

  15. Top 10 Information Classification PowerPoint Presentation ...

    Data classification types ppt icon. Presenting data classification types PPT icon PPT slide. PPT has 100 percent editable content. Ease of addition and deletion of content for the desired level of customization. You may even personalize the presentation with your company specific name and logo.

  16. Functions in C Programming: Types, Arguments, and Reusability

    This lecture discusses the different types of functions in C programming, including void functions with arguments, formal parameters and actual arguments, and the reusability of functions. ... if you can't get a presentation, the file might be deleted by the publisher. E N D . ... • Each actual argument must be of a data type that can be ...