









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These are the Lecture Slides of C Programming which includes Sscanf() Function, Snprintf() Function, Converts String, Floating Point Value, Searches for First Occurrence, Number of Characters, Token Separators, Value of Zero Means etc. Key important ponts are: Functions in C, Function Terminology, Function Declaration, Identifier Scope, Parameters and Arguments, Sample Program, Syntax for Function Declaration, Coding Standards for Functions
Typology: Slides
1 / 16
This page cannot be seen from the preview
Don't miss anything!










int a = 1;
int findMax (int x, int y);
int main (void) { const int j = 10; int k; k = findMax (a, j); return (0); } // End main
int findMax (int x, int y) { int z; if (x < y) z = y; else z = x; a = z; return (z); } // End findMax
Global scope
for variable a
Local scope for j, k
Local scope for x, y, z
Reading from a global variable
Writing to a global variable
float minValue (float x, float y) { if (x < y) return x; else return y; } // End minValue
Coding Standards for Functions
// Include files #include <stdio.h>
// Global constants and types
// Function prototypes
int main (void) { // Function calls
return (0); } // End main
// Function definitions
Output Parameter Example
#include <stdio.h>
int swap ( **int *** x, **int *** y);
int main (void)
{
int a = 27;
int b = 56;
// swap(a, b); // Wrong
swap ( & a, & b); // Right
return(0);
} // End main
"int *" is a pointer type, so the type of x or y is a pointer, which is a memory address
The * here is NOT an operator in this case. It is a decoration that goes with the type
The & is the "address of" operator. It returns the memory address of the variable
This is read as "the address of a"
Output Parameter Example
(continued)
int swap ( **int *** x, **int *** y)
{
int temp;
temp = ***** x;
***** x = ***** y;
***** y = temp;
return(0);
} // End swap
"int *" is a pointer type, so the type of x or y is a pointer, which is a memory address
The * here is NOT an operator in this case. It is a decoration on the variable name
This * here IS an operator. It is called the indirection operator.
In the location named temp, store the value pointed to by x In the location pointed to by x, store the value pointed to by y In the location pointed to by y, store the value in temp Docsity.com
created by declaring the parameter as a pointer to the value that the function will "return" int swap ( **int *** x, **int *** y);
implement "pass by reference"
printf and scanf Functions