DMCA.com Protection Status C Programming – Day 7 | Functions in C Definition, Types & Examples for Beginners - ZAREEN TECH WAVE -Largest Tutorials Website For Freelancer ZAREEN TECH WAVE -Largest Tutorials Website For Freelancer

Header Ads

C Programming – Day 7 | Functions in C Definition, Types & Examples for Beginners

FUNCTIONS IN C

DAY - 7




✅ We keep learning without stopping 🚀


📍 Day-7 — Functions in C

Today we will learn:

✅ What is a function?
✅ Types of functions
✅ Function declaration, definition, calling
✅ Passing arguments
✅ Return values
✅ Task + Quiz


✅ 1️⃣ What is a Function?

📌 A function is a block of code that performs a specific task
📌 Written once — used many times ✅

Example:

#include <stdio.h> void hello(){ printf("Hello, World!"); } int main(){ hello(); return 0; }

✅ 2️⃣ Function Structure

returnType functionName(parameter) { // code return value; // if needed }

Example: Function that returns sum

int add(int a, int b){ return a + b; }

✅ 3️⃣ Function with Parameters & Return

#include <stdio.h> int mul(int x, int y){ return x * y; } int main(){ int result = mul(4, 5); printf("Result = %d", result); return 0; }

✅ 4️⃣ Function Prototype (Declaration)

📌 Write before main() if function defined below

int sum(int, int); // Prototype int main(){ printf("%d", sum(3,4)); } int sum(int a, int b){ return a+b; }

✅ 5️⃣ Types of Functions

TypeExample
No parameter, No returnvoid hello()
Parameter, No returnvoid print(int x)
No parameter, Return valueint roll()
Parameter, Return valueint add(int a,int b)

🧪 Practice Example: Check Even or Odd (Function)

#include <stdio.h> void checkEvenOdd(int n){ if(n % 2 == 0) printf("Even"); else printf("Odd"); } int main(){ int x; scanf("%d", &x); checkEvenOdd(x); }

✅ Task-7

Write a program to:

✔ Create a function named isPrime(int n)
✔ Return:

  • 1 → Prime

  • 0 → Not Prime
    ✔ In main(), input a number and check prime or not

Example Output:

17 is prime

📌 Hint:

  • Prime number has only 2 divisors

  • Use loop from 2 to n/2

✅ Submit your code — I will correct if needed


📝 Quick Quiz — Day-7

Reply like: 1A, 2C, 3B

1️⃣ A function that returns nothing uses:
A) void
B) int
C) float

2️⃣ Which contains the main execution of program?
A) sum()
B) printf()
C) main()

3️⃣ Function prototype is written to:
A) reduce memory
B) tell compiler about function before use
C) stop execution


🎯 After you finish Day-7:

➡ We start Day-8: Pointers 🔥


Whenever you’re ready — send:

👉 Task-7 Code
👉 Day-7 Quiz Answers

I’m here with you till complete success! ✅💪



No comments

Thank You For Visit My Website.
I Will Contact As Soon As Possible.

Theme images by 5ugarless. Powered by Blogger.