Menu
Coddy logo textTech

Recap Challenge

Lesson 11 of 17 in Coddy's Functions in C course.

challenge icon

Challenge

Easy

In C, we can't get the size of an array directly, so we can declare a variable for this and use it to get the size of the array.

 

For example:

int a[] = {1, 2, 3, 4, 5};
int size = sizeof(a) / sizeof(a[0]);

Using the size, write a function to print the values of an array, each on a new line.

Example:

If the input is {"Go", "Java", "React"}

The output should be:

Go
Java
React

 

Try it yourself

#include <stdio.h>

// Function to print the values
void print_array(char* arr[], int size) {
    
}

int main() {
    char* arr[] = {"Python", "Java", "TypeScript", "NodeJs"};
    
    // Calculate the size of the array 
    
    // Call the Function
    print_array(arr, size);

    return 0;
}

All lessons in Functions in C