Skip to main content

Overview of C

PENDAHULUANINTRODUCTION BAHASATO C LANGUAGE

Bahasa C adalahis bahasa pemrogramana general-purpose yangprogramming memilikilanguage kaitanthat eratis denganclosely cararelated kerjato mesinhow komputer.computer Meskipunmachines seringwork. dianggapAlthough sulitoften dipelajari,considered sebenarnyadifficult bahasato learn, C adalahis bahasaactually yanga sederhanasimple namunlanguage memilikiwith kemampuanvast yang luas.capabilities.

BerikutHere beberapaare halsome pentingkey yangpoints perluto diperhatikannote dalam bahasain C:

  • Case-sensitive: Bahasa C membedakandistinguishes antarabetween hurufuppercase besarand danlowercase kecil.letters. Misalnya,For example, printf danand Printf adalahare duatwo haldifferent yang berbeda.things.
  • Space-insensitive: PemisahSeparators sepertisuch spasi,as tab,spaces, atautabs, barisor barunew tidaklines mempengaruhido not affect the program.
  • Semicolon: SetiapEvery pernyataanstatement harusmust diakhiriend denganwith semikolona semicolon (;).
  • Multiple Statements: BeberapaSeveral pernyataanstatements dapatcan ditulisbe dalamwritten satuon baris.the same line.

PROGRAMSIMPLE C SEDERHANA:PROGRAM: MENCETAKPRINTING SEBARISA TEKSLINE OF TEXT

ProgramThe simplest C yangprogram palingis sederhana adalaha program yangthat mencetakprints teks.text. BerikutHere contohis programnya:an example:

#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

Output:

Hello, World!

Bagian-bagianParts of the Program

  1. Comment:

    • Single-line commentcomments menggunakanuse //, atauwhile multi-line commentcomments menggunakanuse /* ... */.
    // IniThis adalahis komentara satusingle-line bariscomment
    /* 
       IniThis adalahis komentara 
       multilinemulti-line comment
    */
    
  2. Header File:

    • Header filefiles sepertilike stdio.h diperlukanare untukrequired menggunakanto fungsiuse sepertifunctions such as printf() atauor scanf().
    #include <stdio.h>
    
  3. Main Function:

    • FungsiThe main() adalahfunction titikis masukthe program.program’s entry point.
    • int main() menunjukkanindicates bahwathat fungsithe mengembalikanfunction nilaireturns an integer (0 untukfor sukses,success, 1 atauor lebihmore untukfor gagal)failure).
    int main() {
        // KodeProgram programcode
        return 0; // MenandakanIndicates successful program selesai dengan suksesexecution
    }
    
  4. FungsiThe printf() Function:

    • FungsiThis inifunction digunakanis untukused mencetakto print output keto layar.the screen.
    • \n adalahis an escape sequence yang berartimeaning newline (barisnew baru)row).
    printf("Hello, World!\n");
    

VARIABELVARIABLES DAN TIPEAND DATA TYPES

VariabelVariables adalahare "wadah"containers" untukfor menyimpanstoring nilai.values. TipeThe data menentukantype jenisdetermines nilaithe yangkind dapatof disimpanvalue dalamthat variabel.can be stored in a variable.

Jenis-jenisTypes Tipeof Data diin C

  1. int - UntukFor bilanganinteger bulat.values.

    int angka1;number1;  // VariabelVariable tanpawithout inisialisasiinitialization (nilairandom acak)value)
    int angka2number2 = 20;  // VariabelVariable denganinitialized inisialisasiwith nilaivalue 20
    
  2. float - UntukFor bilangandecimal pecahan.values.

    float desimaldecimal = 3.14;
    
  3. char - UntukFor menyimpanstoring karaktera tunggal.single character.

    char hurufletter = 'A';
    

BerikutHere gambaris tipea complete diagram of data ditypes Cin yang lebih lengkap:C:
Alt text

MenentukanNaming Nama VariabelVariables

  • NamaVariable variabelnames harusmust dimulaistart denganwith hurufa atauletter or an underscore (_)_).
  • TidakSpaces bolehor menggunakanpunctuation spasi atau tanda bacamarks (sepertisuch as ?, !, dll.etc.). are not allowed.
  • Sensitif case:Case-sensitive: namaname danand NamaName adalahare variabeldifferent yang berbeda.variables.

Contoh:Example:

int umurage = 20;      // Valid
float tinggiheight = 170; // Valid
char namainitial = 'A'; // Valid
int 2umurageOfFather = 45; // Valid

int 2age = 20;     // Tidak validInvalid (dimulaicannot denganstart angka)with a number)

ContohComplete LengkapExample

BerikutHere contohis an example program yangusing menggunakanvariables variabeland dandata tipe data:types:

#include <stdio.h>

int main() {
    int usiaage = 25;
    float tinggi badanheight = 170.5;
    char inisialinitial = 'A';

    printf("Usia:Age: %d tahun\years\n", usia)age);
    printf("Tinggi badan:Height: %.2f cm\n", tinggi badan)height);
    printf("Inisial:Initial: %c\n", inisial)initial);

    return 0;
}

Output:

Usia:Age: 25 tahunyears
Tinggi badan:Height: 170.50 cm
Inisial:Initial: A