Difference between revisions of "C"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(General Skills)
(Examples)
Line 29: Line 29:
  
  
'''String''' is used for storing characters in word form.
+
'''String''' is used for storing characters in word form (note the double quotes "").
  
 
<syntaxhighlight lang="csharp">string example = "hello world";</syntaxhighlight>
 
<syntaxhighlight lang="csharp">string example = "hello world";</syntaxhighlight>
Line 49: Line 49:
  
  
'''Character''' is used to store single letters.
+
'''Character''' is used to store single letters (note the single quotes '').
  
 
<syntaxhighlight lang="csharp">char example = 'A';</syntaxhighlight>
 
<syntaxhighlight lang="csharp">char example = 'A';</syntaxhighlight>
Line 72: Line 72:
  
 
<syntaxhighlight lang="csharp">const int example = 32</syntaxhighlight>
 
<syntaxhighlight lang="csharp">const int example = 32</syntaxhighlight>
 
  
 
==Selection==
 
==Selection==

Revision as of 07:47, 20 June 2019

General Skills

Helloworld

Constants - Variables - Data Types

There are 9 types of data types. These include:

  • boolean
  • string
  • integer
  • double
  • decimal
  • character
  • byte
  • float
  • long

To declare a variable you state the data type followed by the name of the variable:

DataType VariableName;

You can declare and assign a variable at the same time:

DataType VariableName = Value;

Examples

Boolean is a binary value, being either true or false.

bool example = true;


String is used for storing characters in word form (note the double quotes "").

string example = "hello world";


Integer is used to store whole numbers (32 bit values).

int example = 457568368;


Double is used to store numbers where there are numbers before and after the decimal point, using 64 bits of memory.

double example = 3.3;


Decimal is used to store larger numbers with information before and after the decimal point, using 128 bits of memory.

decimal example = 12.593;


Character is used to store single letters (note the single quotes ).

char example = 'A';


Byte is used to store a byte (eight bits). In C#, it is specifically an 8 bit integer (0-255).

byte example = 255;


Float is used to store a 32 bit decimal number, which must be defined as being a float using "F" or "f" to distinguish it from a double, or it may cause compilation errors.

float example = 9.4F;


Long integer is also used to store whole numbers (However these are 64 bit values).

long example = 7846354759340276482;


Constants are used to create a variable of a specified data type that can never be changed after declaration, all global variables should be declared constant. The only way to change it is to edit the code and re-compile.

const int example = 32

Selection

Repetition - Iteration

Operators

Subroutines - Functions

Parameters - Global Variables

Advanced skills

Text Files

Binary Files

Handling Exceptions