C_Programming_Examples
C_Programming_Examples
--------------------------------
Array: A collection of elements of the same data type stored in contiguous memory.
Example:
#include <stdio.h>
#include <string.h>
int main() {
// Array Example
// String Example
return 0;
2. Pointer in C
--------------------------------
Example:
#include <stdio.h>
int main() {
int a = 10;
int *p = &a;
return 0;
--------------------------------
Arrays and pointers are closely related; the name of the array represents the address of its first
element.
Example:
#include <stdio.h>
int main() {
return 0;
4. Functions in C
--------------------------------
Built-in Libraries: Use libraries like #include <math.h>, #include <string.h>, etc.
Example:
#include <stdio.h>
#include <math.h>
void greet() {
int main() {
greet();
return 0;
}
5. Parameter Passing in C
--------------------------------
Example:
#include <stdio.h>
// Call by Value
int temp = x;
x = y;
y = temp;
// Call by Reference
*x = *y;
*y = temp;
int main() {
int a = 5, b = 10;
printf("Before swapValue: a = %d, b = %d\n", a, b);
swapValue(a, b);
swapReference(&a, &b);
return 0;
6. Recursion in C
--------------------------------
(a) Factorial:
Example:
#include <stdio.h>
int factorial(int n) {
if (n == 0 || n == 1)
return 1;
int main() {
int num = 5;
return 0;
Example:
#include <stdio.h>
int fibonacci(int n) {
if (n == 0)
return 0;
if (n == 1)
return 1;
int main() {
return 0;