Advertisement
Niloy007

Function & Pointer

Nov 8th, 2020
1,858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. // Function Declaration
  4.  
  5. /*
  6.  
  7. returnType functionName(parameter) {
  8.  
  9. }
  10.  
  11. */
  12.  
  13.  
  14.  
  15. double mul(double numOne, double numTwo) {
  16.     double x = numOne * numTwo;     // Local variable
  17.  
  18.     return x;
  19. }
  20.  
  21. double div(double numOne, double numTwo) {
  22.     double x;
  23.     if (numTwo == 0) {
  24.         x = -1;
  25.     } else {
  26.         double x = numOne / numTwo;     // Local variable
  27.     }
  28.  
  29.     return x;
  30. }
  31.  
  32. int numOne, numTwo;
  33.  
  34. void Fun() {
  35.     scanf("%d %d", &numOne, &numTwo);
  36.     printf("In Function: \n");
  37.     printf("NumOne = %d, NumTwo = %d\n", numOne, numTwo);
  38. }
  39.  
  40. // void hello() {
  41. //  printf("Hello world\n");
  42. // }
  43.  
  44.  
  45. int main() {
  46.     scanf("%d %d", &numOne, &numTwo);
  47.     printf("\nIn Main Func: \n");
  48.     printf("NumOne = %d, NumTwo = %d\n", numOne, numTwo);
  49. }
  50.  
  51. // int main() {
  52. //  int arr[5] = {1, 2, 3, 4, 5};
  53. //  int *p;
  54. //  p = &arr[0];
  55. //  printf("%p\n", p);
  56.  
  57.     // for (int i = 0; i < 5; i++) {
  58.     //  printf("%d ", *(p + i));
  59.     // }
  60.     // printf("\n");
  61.  
  62.     // int var = 10;
  63.     // int var2 = 20;
  64.     // int *p, *q;
  65.     // p = &var;
  66.     // q = &var2;
  67.     // printf("%p %p\n", p, q);
  68. // }
  69.  
  70. /*
  71.     -> Pointer      // pointer er kaj holo address niye kaj kora
  72.     -> Function
  73.         -> Function Declaration
  74.         -> With Parameter and without parameter
  75.         -> void
  76.         -> Pass by value
  77. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement