Sie sind auf Seite 1von 2

Date: 09/19/2013

Prepared by Rohit Dashrathi

MEEM 5705: Intro to Robotics and Mechatronics

Instructor: Dr. Rastgaar

Basic C concepts

What is a preprocessor?

What is a directive?

What is a header?

It is the entity that preprocesses certain required file before the program starts
e.g. #include is a preprocessing directive. Because it activates the header files in <> brackets which are
needed for program to run. #include<stdio.h> preprocesses the header file stdio.h which loads standard
input output library in the program.

Directives: They direct how a compiler should process its input


e.g. #include, #define

It is a file containing C declarations and macro definitions.


You request the use of a header file in your program by including it, with the C preprocessing directive
#include.
Common header files : stdio.h, conio.h,math.h
e.g. #include<stdio.h> opens stdio.h and copy its contents into the program

Some common headers?


stdio.h: This library uses what are called streams to operate with physical devices such as keyboards,
printers, terminals or with any
other type of files supported by the system.
math.h: Declares a set of functions to compute common mathematical operations and transformations:e.g.
trigonometric, exponential
etc.
conio.h: Contain functions for console input/output. Some of the most commonly used functions of conio.h are clrscr,
getch, getche, kbhit
etc. Functions of conio.h can be used to clear screen, change color of text and background, move
text, check if a key is pressed or not and many more.

What is int main()?


It is the function is where a program starts execution.

Date: 09/19/2013
Prepared by Rohit Dashrathi

MEEM 5705: Intro to Robotics and Mechatronics

Instructor: Dr. Rastgaar

What is the difference between int main() and void main()?


Technically, nothing. Only that the void main() is outdated. Just use int main() and don't worry about the
other one.

What is printf?

What is scanf?

What is return statement?

Prints the message on the screen


e.g. printf("Enter a number: ");

Syntax: scanf("%d",&variable);
%d : scans if the input value entered is integer or not
&variable: points the input value entered to a variable

A function may or may not return a value. A return statement returns a value to the calling function and
assigns to the variable.
return void: Used in case when program does not want an output value.
return 0: it signifies that the program execution was successful. returns an error code in case of an error.

What are pointers?

What are functions?

Those are variables which point to another variable


: indirection operator
&: address operator
Do not use operator on variable side when assigning a value to it.
e.g. *variable=a; is not correct. instead, use variable=&a.

Series of statements that are grouped together and given a name.


Break large tasks into smaller ones and lets you use previous work without rewriting everything from scratch

Das könnte Ihnen auch gefallen