1) What Is C Language?
1) What Is C Language?
1) What Is C Language?
scanf(): The scanf() function is used to take input from the user.
Storage Variables are stored in a stack unless The compiler decides the storage
specified. location of a variable.
o C functions are used to avoid the rewriting the same code again and again in
our program.
o C functions can be called any number of times from any place of our program.
o When a program is divided into functions, then any part of our program can
easily be tracked.
o C functions provide the reusability concept, i.e., it breaks the big task into
smaller tasks so that it makes the C program more understandable.
Description When a copy of the value is passed to When a copy of the value is passed to
the function, then the original value is the function, then the original value is
not modified. modified.
Safety In this case, actual arguments remain In this case, actual arguments are not
safe as they cannot be modified. reliable, as they are modified.
Arguments The copies of the actual arguments are The addresses of actual arguments
passed to the formal arguments. are passed to their respective formal
arguments.
1. #include <stdio.h>
2. void change(int,int);
3. int main()
4. {
5. int a=10,b=20;
6. change(a,b); //calling a function by passing the values of variables.
7. printf("Value of a is: %d",a);
8. printf("\n");
9. printf("Value of b is: %d",b);
10. return 0;
11. }
12. void change(int x,int y)
13. {
14. x=13;
15. y=17;
16. }
Output:
Value of a is: 10
Value of b is: 20
1. #include <stdio.h>
2. void change(int*,int*);
3. int main()
4. {
5. int a=10,b=20;
6. change(&a,&b); // calling a function by passing references of variables.
7. printf("Value of a is: %d",a);
8. printf("\n");
9. printf("Value of b is: %d",b);
10. return 0;
11. }
12. void change(int *x,int *y)
13. {
14. *x=13;
15. *y=17;
16. }
Output:
Value of a is: 13
Value of b is: 17
1. Winding phase
2. Unwinding phase
Winding phase: When the recursive function calls itself, and this phase ends when
the condition is reached.
Unwinding phase: Unwinding phase starts when the condition is reached, and the
control returns to the original call.
Example of recursion
1. #include <stdio.h>
2. int calculate_fact(int);
3. int main()
4. {
5. int n=5,f;
6. f=calculate_fact(n); // calling a function
7. printf("factorial of a number is %d",f);
8. return 0;
9. }
10. int calculate_fact(int a)
11. {
12. if(a==1)
13. {
14. return 1;
15. }
16. else
17. return a*calculate_fact(a-1); //calling a function recursively.
18. }
Output:
Syntax:
1. data_type array_name[size];
o Multidimensional array: Multidimensional array is an array that contains
more than one array.
Syntax:
1. data_type array_name[size];
Example of an array:
1. #include <stdio.h>
2. int main()
3. {
4. int arr[5]={1,2,3,4,5}; //an array consists of five integer values.
5. for(int i=0;i<5;i++)
6. {
7. printf("%d ",arr[i]);
8. }
9. return 0;
10. }
Output:
1 2 3 4 5
For example:
1. Data_type *p;
The above syntax tells that p is a pointer variable that holds the address number of a
given data type value.
Example of pointer
1. #include <stdio.h>
2. int main()
3. {
4. int *p; //pointer of type integer.
5. int a=5;
6. p=&a;
7. printf("Address value of 'a' variable is %u",p);
8. return 0;
9. }
Output: