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.
Pointers are among C’s most powerful, yet most difficult concepts to master. Some tasks like dynamic memory allocation done only by using pointers. So it is essential to learn pointers.
Pointers are a type of variable, just like int, double, etc., except instead of storing a value, they store a memory address of another variable.
This Presentation gives you all knowledge about #CPointers, #PointersInC.
The given slides are as follows:
1. Introduction of Pointers.
2. Systems to create a pointer in C.
3. Valid Pointer Examples in C.
4. Graphical representation of address assigning in c using pointer.
5. 1st Sample program of pointers in C.
6. Types of Pointers
7. NULL Pointer in C (Types of Pointer)
8. void Pointer in C (Types of Pointer)
9. Wild Pointer in C (Types of Pointer)
10. Changing value of variable using pointer
11. Update and Access value of variable using pointer in example.
12. Types of format specifies to print address in different format.
13. Advantages of Pointer in C.
14. Disadvantages of Pointer in C.
15. Pointers with Array using Programs. #pointerwitharray
16. Another Example of #pointerwitharray.
17. Relationship Between Arrays and Pointers.
18. Relationship Between Arrays and Pointers explanation with diagram.
19. Pointers and String. #PointersAndString
20. Function with Array Parameters using pointers.
21. Passing Pointers to Function or Pointer argument function. #PointerWithFunction
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.
Pointers are among C’s most powerful, yet most difficult concepts to master. Some tasks like dynamic memory allocation done only by using pointers. So it is essential to learn pointers.
Pointers are a type of variable, just like int, double, etc., except instead of storing a value, they store a memory address of another variable.
This Presentation gives you all knowledge about #CPointers, #PointersInC.
The given slides are as follows:
1. Introduction of Pointers.
2. Systems to create a pointer in C.
3. Valid Pointer Examples in C.
4. Graphical representation of address assigning in c using pointer.
5. 1st Sample program of pointers in C.
6. Types of Pointers
7. NULL Pointer in C (Types of Pointer)
8. void Pointer in C (Types of Pointer)
9. Wild Pointer in C (Types of Pointer)
10. Changing value of variable using pointer
11. Update and Access value of variable using pointer in example.
12. Types of format specifies to print address in different format.
13. Advantages of Pointer in C.
14. Disadvantages of Pointer in C.
15. Pointers with Array using Programs. #pointerwitharray
16. Another Example of #pointerwitharray.
17. Relationship Between Arrays and Pointers.
18. Relationship Between Arrays and Pointers explanation with diagram.
19. Pointers and String. #PointersAndString
20. Function with Array Parameters using pointers.
21. Passing Pointers to Function or Pointer argument function. #PointerWithFunction
Functions - C Programming
What is a Function? A function is combined of a block of code that can be called or used anywhere in the program by calling the name. ...
Function arguments. Functions are able to accept input parameters in the form of variables. ...
Function return values
View study notes of Function overloading .you can also visit Tutorialfocus.net to get complete description step wise of the concerned topic.Other topics and notes of C++ are also explained.
Functions - C Programming
What is a Function? A function is combined of a block of code that can be called or used anywhere in the program by calling the name. ...
Function arguments. Functions are able to accept input parameters in the form of variables. ...
Function return values
View study notes of Function overloading .you can also visit Tutorialfocus.net to get complete description step wise of the concerned topic.Other topics and notes of C++ are also explained.
Online storefront creation: A business creates an online storefront, which serves as its virtual shop where customers can browse products or services, place orders, and make payments.
Product listing: The business lists its products or services on the online storefront, along with relevant information such as price, product description, and images.
Payment gateway integration: The business integrates a payment gateway into its online storefront, which allows customers to securely make payments online using credit cards, debit cards, or other payment methods.
Order processing: When a customer places an order, the business receives the order information through the online storefront. The business then processes the order, which may involve verifying the availability of the product, preparing the product for shipping, and generating a shipping label.
Shipping and delivery: The business ships the product to the customer's address using a third-party logistics provider or its own delivery service. The customer is provided with tracking information to monitor the status of the shipment.
Customer service: The business provides customer service to address any issues or concerns that the customer may have regarding the product or service.
Example:
Let's take the example of a clothing store that sells its products online through its e-commerce website. The store creates an online storefront and lists its products, which include dresses, shirts, pants, and accessories. Customers can browse the products, select the items they wish to purchase, and make payments online using a payment gateway such as PayPal or Stripe.
Once the order is received, the store processes the order and prepares the product for shipping. The product is then shipped to the customer's address using a logistics provider such as FedEx or UPS. The customer can track the shipment using the tracking information provided by the store.
If the customer is not satisfied with the product, they can contact the store's customer service and initiate a return or exchange. The store handles the return or exchange process and ensures that the customer is satisfied with their purchase.
2. Functions
A function is a self contained block of code that performs a
particular task.
Any C program can be seen as a collection/group of these
functions.
A functions takes some data as input, perform some
operation on that data and then return a value.
Any C program must contain at least one function, which is
main().
There is no limit on the number of functions that might be
present in a C program.
3. For ex.
main()
{
message();
printf(“I am in main”);
}
message()
{
printf(“I am in message”);
}
4. Function Prototype
All Identifiers in C must be declared before they are used. This is true
for functions as well as variables.
For functions, the declarations needs to be done before the first call of
the function.
A function declaration specifies the name, return type, and arguments
of a function. This is also called the function prototype.
To be a prototype, a function declaration must establish types for the
function’s arguments.
Having the prototype available before the first use of the function
allows the compiler to check that the correct number and types of
arguments are used in the function call.
5. The prototype has the same syntax as the function
definition, except that it is terminated by a semicolon
following the closing parenthesis and therefore has no
body.
Although, functions that return int values do not require
prototypes, prototypes are recommended.
6. Function Definition
General form of any function definition is:
return-type function-name(argument declarations)
{
declarations and statements
}
Return-type refers to the data type of the value being
returned from the function. If the return type is omitted,
int is assumed.
The values provided to a function for processing are the
arguments.
The set of statements between the braces is called as the
function body.
7. Arguments – Call by Value
In C, all functions are passed “by value” by default.
This means that the called function is given the values of its
arguments in temporary variables rather than the originals.
For ex. main()
{
int a=4,b=5;
sum(a,b);
printf(“Sum = %d”,a+b);
}
sum(int a,int b)
{
a++;
b++;
printf(“Sum = %d”,a+b);
}
8. Arguments – Call by Reference
When necessary, it is possible to arrange a function which can modify a
variable in a calling routine.
The caller must provide the address of the variable to be set (generally, a
pointer to a variable), and the called function must declare the parameter to
be a pointer and access the variable indirectly through it.
For ex: main()
{
int a=4,b=5;
sum(&a,&b);
printf(“Sum = %d”,a+b);
}
sum(int *a,int *b)
{
(*a)++;
(*b)++;
printf(“Sum = %d”,(*a)+(*b));
}
9. Recursion
Recursion defines a function in terms of itself.
It is a programming technique in which a function calls
itself.
A recursive function calls itself repeatedly, with different
argument values each time.
Some argument values cause the recursive method to
return without calling itself. This is the base case.
Either omitting the base case or writing the recursion step
incorrectly will cause infinite recursion (stack overflow
error).
10. Recursion to find the factorial of any number:
int factorial(int x)
{
if(x<=1)
return 1;
else
return(x*factorial(x-1));
}
11. External Variables
See the below example:
main()
{
extern int a;
printf(“Value of a = %d”,a);
}
int a=5;
Output: Value of a = 5
12. Scope Rules
Example:
int num1 = 100; //Global Scope
static int num2 = 200; //File Scope
int main()
{
int num3 = 300; //Local Scope
if(num2>num1)
{
int i=0; //Block Scope
printf(“Value of i = %dn”,i++);
}
printf(“Value of num1 = %dn”,num1);
printf(“Value of num2 = %dn”,num2);
printf(“Value of num3 = %dn”,num3);
}
13. Static Variables
Example:
static int min = 10;
int setmax()
{
static int max = 100;
return ++max;
}
main()
{
min++;
printf(“Value of max = %d”, setmax());
printf(“Value of max = %d”, setmax());
printf(“Value of min = %d”, min);
}