C provides several key features that make it powerful and popular.
structure_name {
data_type member1;
data_type member2;
};`
and you can access members using the dot operator (e.g.,`student.name`).
objective-cint factorial(int n) { if (n == 0) return 1; // Base case return n * factorial(n - 1); // Recursive case }
objective-ctypedef int* IntPtr; IntPtr ptr1, ptr2; // ptr1 and ptr2 are both pointers to integers
objective-cint add(int a, int b) { return a + b; // Returns the sum of a and b }
objective-cvoid modifyArray(int arr[]) { arr[0] = 100; // Modifies the original array }
objective-cint arr[5] = {1, 2, 3, 4, 5}; // Declare an array of 5 integers
objective-cconst int x = 10; // x cannot be modified const int *ptr = &x; // ptr points to a constant value
objective-cint *ptr = NULL;
objective-cint add(int a, int b) { return a + b; } int subtract(int a, int b) { return a - b; } int (*operation)(int, int); // Declare a function pointer operation = add; // Assign the function pointer printf("%d", operation(3, 4)); // Call the function through the pointer
objective-c#define PI 3.14 #define MAX(a, b) ((a) > (b) ? (a) : (b))
While macros are useful, they should be used carefully since they can lead to unexpected behaviors due to lack of type checking.
Copyrights © 2024 letsupdateskills All rights reserved