C Program to Print Fibonacci Series Using Pointers

In this program, we will print Fibonacci Series using pointers. The pointer is a variable which stores the address of another variable. This variable can be of type int, char, array, function, or any other pointer. The size of the pointer depends on the architecture. However, in 32-bit architecture the size of a pointer is 2 byte. Unlike other variables that hold values of a certain type, pointer holds the address of a variable. For example, an integer variable holds (or stores) an integer value, however an integer pointer holds the address of a integer variable.

Source Code
void main()
    int i, term;
    int *ptr;
    int first=0, second=1, next;
    ptr = &term;
    printf("How many terms: ");
    scanf("%d", &term);
    printf("FIBONACCI SERIES: ");
    printf("%d %d", first, second);
    for(i=2; i<*ptr; i++)
        next = first + second;
        printf(" %d", next);
        first = second;
        second = next;
How many terms: 10
FIBONACCI SERIES: 0 1 1 2 3 5 8 13 21 34

"Coding Hub - Learn to code" app now available on Google Play Store