Sunday, July 24, 2011

C All-in-One Desk Reference For C Beginer's

Cheat Sheet

C All-in-One Desk Reference For C Beginer's

Written by:- Dan Gookin

When working in the C programming language, you need to be familiar with how C does things — for example, its order of precedence, variable types, operators, and comparisons and their opposites.

Order of Precedence in C Programming Language

If you're programming with C, you're using operators — and knowing whether to read those operators from left to right or right to left means writing a C program that works and one that crashes. Use the information in the following table to determine the order of precedence in C:

C Language Variable Types

Whether you're working with regular or unsigned variables in your C program, you need to know a bit about those various variables. The following table show C variable types, their value ranges, and a few helpful comments:

C Language Operators

In programming with C, you occasionally want to use common mathematical operators for common mathematical functions and not-so-common operators for logic and sequence functions. Here's a look at C language operators to use:
Operator, Category, Duty
Operator, Category, Duty
Operator, Category, Duty
=, Assignment, Equals
!=, Comparison, Is not equal to
>, Bitwise, Shift bits right
+, Mathematical, Addition
&&, Logical, AND
~, Bitwise, One's complement
–, Mathematical, Subtraction
||, Logical, OR
+, Unary, Positive
*, Mathematical, Multiplication
!, Logical, NOT
–, Unary, Negative
/, Mathematical, Division
++, Mathematical, Increment by 1
*, Unary, Pointer
%, Mathematical, Modulo
--, Mathematical, Decrement by 1
&, Unary, Address
>, Comparison, Greater than
&, Bitwise, AND
sizeof, Unary, Returns the size of an object
>=, Comparison, Greater than or equal to
|, Bitwise, Inclusive OR
., Structure, Element access
<, Comparison, Less than
^, Bitwise, Exclusive OR (XOR or EOR)
->, Structure, Pointer element access
<=, Comparison, Less than or equal to
<<, Bitwise, Shift bits left
?:, Conditional , Funky if operator expression
==, Comparison, Is equal to

C Language Comparisons and Their Opposites

Programming in C, or any programming language, means building comparisons — greater and lesser than and equal to in various combinations. Get to know the comparisons C uses and their opposites:
If Comparision
Else Statement Executed By
This Condition
Greater than or equal to
Not equal to
Less than or equal to
Greater than
Less than
Equal to

C Language Comparison Symbols

If you’re writing programs in C, you need to use comparison symbols. The symbols C uses, their meanings, and examples are shown in the following table:
Meaning or Pronunciation
“True” Comparison Examples
Less than
1 < 5
8 < 9
Equal to
5 == 5
0 == 0
Greater than
8 > 5
10 > 0
Less than or equal to
4 <= 5
8 <= 8
Greater than or equal to
9 >= 5
2 >= 2
Not equal to
1 != 0
4 != 3.99

C Language Conversion Characters

When programming in C, you use conversion characters — the percent sign and a letter, for the most part — as placeholders for variables you want to display. The following table shows the conversion characters and what they display:
Conversion Character
Displays Argument (Variable’s Contents) As
Single character
Signed decimal integer (int)
Signed floating-point value in E notation
Signed floating-point value (float)
Signed value in %e or %f format, whichever is shorter
Signed decimal integer (int)
Unsigned octal (base 8) integer (int)
String of text
Unsigned decimal integer (int)
Unsigned hexadecimal (base 16) integer (int)
(percent character)

C Language Escape Sequences

Programming in C is fast — all you have to do is type a short sequence of keystrokes — generally just two — to get a tab, a new line, a question mark, and more. The following table shows the sequences you need to accomplish a variety of tasks:
The speaker beeping
Backspace (move the cursor back, no erase)
Form feed (eject printer page; ankh character on the screen)
Newline, like pressing the Enter key
Carriage return (moves the cursor to the beginning of the line)
Vertical tab (moves the cursor down a line)
The backslash character
The apostrophe
The double-quote character
The question mark
The “null” byte (backslash-zero)
A character value in hexadecimal (base 16)
A character value in hexadecimal (base 16)

C Language Keywords

The C programming language has just 32 keywords for you to build robust programs. With only 32 keywords, they all fit nicely into a short table. Use them wisely and well.





C Language Numeric Data Types

When programming with C, keywords and variables go together like the 4th of July and fireworks, although with a bit less drama. The following table shows C keywords, their variable types, and their ranges:

C Language Mathematical Symbols

Programming math functions with C is fairly straightforward: a plus sign works like any sixth-grader knows it should and does addition. The mathematical symbols and the function they serve in C are shown in the following table:

No comments:

Post a Comment

Hey Guys What You Think about this blog?