☠️
smadi0x86 Playground
  • 💀Welcome to smadi0x86 Playground
    • 🍷Resources
    • 🚬Projects
    • 🎓Certifications
    • 📌Pinned
    • ❓Questions
    • 📞Contact
  • 🏞️Cloud Native
    • Docker
      • Quick Reference
      • Introduction
      • Containers
      • Images
      • Storage & Volumes
      • Security
      • Cheatsheet
    • Git
    • Serverless Framework
    • YAML
  • 🔨Software Engineering
    • System Design
    • Environment Variables
    • JSON Web Tokens
  • 👾Architecture
    • C Language
      • Introduction
      • Calling Conventions
      • GCC Compilation
      • Libraries & Linking
      • I/O
      • Files
      • Pointers
      • Dynamic Memory Allocation
      • Data Types
      • Strings Manipulation
      • Bit Manipulation
      • Pre-processors
      • Macros
      • Type Qualifiers
    • C/C++ Build Systems
      • Fundamentals for Linking
      • Symbolic Linking
      • Cross-Platform Compilation
      • CMake for Building and Linking
      • Shared Libraries
      • Dynamic Linking and Dependency Management
    • Operating Systems
      • OS & Architecture
      • Processes
      • CPU Scheduling
      • Memory Management
  • 🛩️Cyber Warfare
    • Flight Physics
    • Communication
      • PWM & PPM
      • MAVLink
  • 🏴‍☠️Offensive Security
    • Active Directory
      • Introduction
    • Web Attacks
      • Server Side
        • OS Command Injection
        • Information Disclosure
        • Directory Traversal
        • Business Logic
        • Authentication
        • File Upload
        • SSRF
      • Client Side
        • CSRF
        • XSS
    • Recon
      • Active
        • Host discovery
        • Nmap
        • Mass Scan
      • Passive
        • Metadata
      • Web Applications
        • Discovery
        • Subdomains & Directories
        • SSL Certs
        • CMS
        • WAF Detection
      • Firewall Evasion
  • Binary Exploitation
    • Stack Smashing
      • x86
      • x86_64
    • pwntools
      • Processes and Communication
      • Logging and Context
      • Cyclic
      • Packing
      • ELF
      • ROP
  • 😈Advanced Persistent Threat
    • C2
      • Sliver
    • Malware
      • Windows Internals
        • PEB
      • Academy
        • Basics
      • Sektor7
        • Essentials
  • 💌Certifications
    • AWS Certified Cloud Practitioner (CLF-C01)
      • Cloud Foundations
      • Domain 1: Cloud Concepts
      • Domain 2: Security and Compliance
      • Domain 3: Technology
      • Domain 4: Billing and Pricing
    • AWS Certified Solutions Architect - Associate (SAA-C03)
      • Foundation
    • Certified Kubernetes Administrator (CKA)
      • Core Concepts
      • Scheduling
      • Logging & Monitoring
      • Application Lifecycle Management
      • Cluster Maintenance
      • Security
      • Storage
      • Networking
      • Design Kubernetes Cluster
      • Kubernetes The Kubeadm Way
      • Troubleshooting
      • JSONPATH
      • Lightning Lab
      • Mock Exams
      • Killer Shell
    • Certified Kubernetes Security (CKS)
      • Foundation
      • Cluster Setup
      • Cluster Hardening
      • Supply Chain Security
      • Runtime Security
      • System Hardening
      • Killer Shell
    • (KGAC-101) Kong Gateway Foundations
      • Introduction to APIs and API Management
      • Introduction to Kong Gateway
      • Getting Started with Kong Enterprise
      • Getting Started with Kong Konnect
      • Introduction to Kong Plugins
  • 📜Blog Posts
    • Modern Solutions For Preventing Ransomware Attacks
Powered by GitBook
On this page
  • Integer
  • Boolean
  • size_t
  • wchar_t
  • char
  • Escape Characters
  • Data Type Conversion Functions
  • Printing Format Strings
  • Typedef
  • Operators
  • Difference between x++ and ++x
  • Logical Operators
  1. Architecture
  2. C Language

Data Types

Integer

int is typically 4 bytes.

_t is types that are designed to be cross-platform compatible, which means they include the given number of bytes no matter what system they run on.

You can specify any byte size to int using:

uint32_t // This is an int that holds 32 bytes (0 to 4294967295)
// or
int32_t // -2147483648 to 2147483647

You don't have to specify the u = unsigned, it's commonly used to represent the values that are non-negative which saves memory space.

Boolean

Boolean data type for storing 0 or 1 values.

Used for on/off, yes/no, true/false situation (binary choices).

Include <stdbool.h> to use bool instead of _Bool.

#include <stdbool.h>

bool var = true;
   
// Or we can do:

    _Bool y = 1; // True
    _Bool n = 0; // False


// Or use preprocessors (have to include stdbool header):

#define true 1
#define false 0

#define yes true
#define no false

size_t

size_t → Used to represent the size of objects in bytes and is therefore used as the return type by the sizeof operator.

size_t is a type guaranteed to hold any array index only for non-negative values.

size_t s1 = strlen(str1);
printf("%zu", s1);

wchar_t

wchar_t → Wide char is similar to char data type, except that wide char take up twice the space and can take on much larger values as a result.

Char can take 256 values which corresponds to entries in the ASCII table.

On the other hand, wide char can take on 65536 values which corresponds to UNICODE values which is a recent international standard which allows for the encoding of characters for virtually all languages and commonly used symbols.

Example:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    wchar_t *s;

    s = (wchar_t *)malloc(sizeof(wchar_t) * 2);
    s[0] = 42;   // ascii code for *
    s[1] = 115;   // ascii code for 's'
    
    printf("%ls\n", s);
    free(s);
    
    return 0;
}

char

Represents a single character such as the letter 'a'.

Char always uses single quotes.

var = 't';

char grade = 65; → is valid for ASCII code but not recommended.

Escape Characters

 \a → alert
 \b  → backspace
 \f → form feed
 \n → new line
 \r → carriage  return
 \t → horizental tab
 \v → vertical tab
 \\ → backslash \
 \' → single quote
 \" → double quote
 \? → question mark ?

Data Type Conversion Functions

 double a = atof(s) → // Converts the string into a floating-point number, returning the result
 
 int a = atoi(s) → // Converts the string into an int, returning the result
 
 int a = atol(s) → // Converts the string into a long int, returns result
 
 int a = atoll (s) → // Converts string into long long int, returns result 

Printing Format Strings

Typedef

A keyword that allows us to create our own name for an existing data type.

Defines the name counter to be equal to the C data type int.

Now variables can be declared of type counter:

 typedef int counter;

Operators

+ → add  
- → subtract
* → multiply
/ → divide
% → remainder of division
++ → increment by one
-- → decrement by one
= → simple assign operator
+= → add and assign
-= → subtract and assign
*= → multiply and assign
/= → devide and assign
%= → modulus and assign
<< → left shift operator, i.e: 1 << 0 == 2 to the power of 0 == 1 == binary 0001
>> → right shift operator
>>= → right shift and assign
<<= → left shift and assign
&= → bitwise and assign
^= → bitwise exclusive or and assign
|= → bitwise inclusive or and assign

Example:

#include <stdio.h>

int main(){
    unsigned int a = 60; // 0011 1100
    unsigned int b = 13; // 0000 1101
    int result = 0;
    int c = a & b; // 0000 1100
    
    printf("result: %d", c);
    
    return 0;
}

Difference between x++ and ++x

++x happens prior to assignment (per-increment).

x++ happens after assignment (post-increment).

x++ executes the statement and then increments the value.

++x increments the value and then executes the statement.

Logical Operators

&& → AND operator, if both are non-zero the condition is true (A && B) is false.

|| → OR operator, if any or both are non-zero the condition is true (A || B) is true.

! → NOT operator, reverse the logical statement !(A && B) is true.

 (A || B) ? printf("true") : printf("false");
 (A && B) ? printf("true") : printf("false");
PreviousDynamic Memory AllocationNextStrings Manipulation

Last updated 8 months ago

👾