C header structure

From ATI public wiki
Revision as of 20:59, 15 December 2014 by Hkinks (Talk) (Created page with "==sample.h== <source lang="c" collapse="false" first-line="2"> include guard - ei lase funktsioone üle defineerida: #ifndef SAMPLE_H #define SAMPLE_H /* Funktsiooni dek...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

sample.h

/* include guard - ei lase funktsioone üle defineerida*/
#ifndef SAMPLE_H 
#define SAMPLE_H

/* Funktsiooni deklaratsioon */
int sample(int a);

#endif

sample.c

#include "sample.h"

int sample(int a) {
  /* Funktsiooni definitsioon */
  return a * a;
}

main.c

#include <stdio.h>
#include "sample.h"

int main(void) {
  int a = sample(4);
  printf("%d\n", a);
  return 0;
}