Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Programming Languages

05 Hands-on Activity 1

Data Types

Programming language: C

Built-in data types:

Int - integers are for storing whole numbers, whether positive, negative, or zero, without
any decimal parts.

Float - floats are for holding numbers with decimal points, allowing you to work with
values that aren't whole numbers. They're not as precise as doubles.

Double - doubles are similar to floats but offer more precision. They're used for numbers
with decimal points when you need extra accuracy.

Char - chars are for storing individual characters, like letters, numbers, or symbols,
typically in the ASCII format. They're useful for dealing with text.

Void - void is a special type that means "nothing" or "absence." It's often used in
functions that don't return any value, indicating that the function does its job without
giving back data.

Sample statements:
#include <stdio.h>

int main() {
// Integer
int integerValue = 42;
printf("Integer value: %d\n", integerValue);

// Float
float floatValue = 3.14;
printf("Float value: %.2f\n", floatValue);

// Double
double doubleValue = 3.14159265359;
printf("Double value: %lf\n", doubleValue);

// Char
char charValue = 'A';
printf("Char value: %c\n", charValue);

Programming language: Ruby

Built-in data types:

Integer: Integers represent whole numbers, positive or negative, without any decimal
point.

Float: Floats represent numbers with a decimal point, allowing for fractional values.

String: Strings are sequences of characters enclosed within either single or double
quotation marks.

Array: Arrays are ordered collections of objects, indexed by integers starting from 0.

Hash: Hashes, also known as dictionaries or associative arrays in other languages, are
collections of key-value pairs.

Boolean: Booleans represent either true or false values.

Symbol: Symbols are immutable identifiers often used as keys in hashes or for efficient
comparison.

Sample statements:
# Integer
integer_value = 42
puts "Integer value: #{integer_value}"

# Float
float_value = 3.14
puts "Float value: #{float_value}"

# String
string_value = "Hello, world!"
puts "String value: #{string_value}"

# Array
array_value = [1, 2, 3, 4, 5]
puts "Array value: #{array_value}"

# Hash
hash_value = { "name" => "John", "age" => 30 }
puts "Hash value: #{hash_value}"

# Boolean
boolean_value = true
puts "Boolean value: #{boolean_value}"

# Symbol
symbol_value = :foo
puts "Symbol value: #{symbol_value}"

You might also like