C - Passing constant values to a function

Introduction

Functions don't necessarily need to consume variables.

The display() function in the following code can accept any int value, including an immediate value or a constant.

Demo

#include <stdio.h>

void display(int count);

int main()//ww  w  .j a  v  a  2  s  .c o m
{
    int value;

    value = 2;

    display(64);
    printf("Value is %d\n",value);
    value = value * 2;

    return(0);
}

void display(int count)
{
    int x;

    for(x=0;x<count;x=x+1)
        putchar('*');
    putchar('\n');
}

Result

Related Topic