Selasa, 25 Maret 2014

Exercise 3.36

3.36 (Printing the Decimal Equivalent of a Binary Number)

Input an integer containing only 0s and 1s (i.e., a “binary” integer) and print its decimal equivalent. [Hint: Use the remainder and division operators to pick off the “binary” number’s digits one at a time from right to left. Just as in the decimal number system, in which the rightmost digit has a positional value of 1, and the next digit left has a positional value of 10, then 100, then 1000, and so on, in the binary number system the rightmost digit has a positional value of 1, the next digit left has a positional value of 2, then 4, then 8, and so on. Thus the decimal number 234 can be interpreted as 4 * 1 + 3 * 10 + 2 * 100. The decimal equivalent of binary 1101 is 1 * 1 + 0 * 2 + 1 * 4 + 1 * 8 or 1 + 0 + 4 + 8 or 13.]

C Program: 
#include <stdio.h>
 

int binary_conversion(int);

int main()

{

   int num, bin;

   printf("Enter a decimal number: ");

   scanf("%d", &num);

   bin = binary_conversion(num);

   printf("The binary equivalent of %d is %d\n", num, bin);

   system("pause");

}

 

int binary_conversion(int num)

{

    if (num == 0)

    { return 0; }

    else

    { return (num % 2) + 10 * binary_conversion(num / 2);  }

}
Output:

Explain about Promotion and Explicit Conversion in C

Promotion Conversion
Promotion Conversion adalah tipe pengkonversian type data sesuai dengan tipe data operan. Dengan kata lain, promotion conversion akan secara otomatis menyesuaikan tipe data lama, dan diganti dengan tipe data baru sesuai tipe data dari operan yang digunakan.

Contoh:
short a = 5;
int b = 2;
int c;
c=a*b;
Secara otomatis, hasil perkalian dari a dan b akan bertipe integer, karena mengikuti tipe data dari variabel c walaupun pada awalnya variabel a bertipe data short.

Explicite Conversion
Tipe explicite conversion atau biasa disebut casting memungkinkan untuk mengkonversi data yang sudah diberikan ke tipe data yang lain. Ada beberapa cara yang dapat dilakukan, yang paling popiler yaitu tipe baru dituliskan dalam tanda kurung ().

Contoh:
int eksplisit; float jari_jari=3.14; eksplisit = (int)jari_jari;
Tipe eksplisit yang digunakan dalam contoh diatas adalah "(int)", yang berarti mengkonversi nilai dari jari_jari yang sebelumnya bertipe float dan bernilai 3,14 diubah menjadi integer sehingga nilai dari eksplisit sekarang berbubah menjadi 3.

Explain about Signed and Unsigned data type

Signed variabel adalah sebuah variabel yang nilainya/range nya selalu lebih dari nol. Yang artinya selalu bernilai positif. Sedangkan Unsigned variabel nilainya bisa dibawah nol (negatif), nol, ataupun lebih dari 0.

Dibawah ini adalah range dari beberapa type variabel yang bersifat signed dan unsigned:
  • Char => Signed : -128 sampai 127 || Unsigned : 0 sampai 255
  • Integer => Signed :  32768 sampai 32767 || Unsigned : 0 sampai 65535
  • Long integer => Signed: -2147483648 sampai 2147483647 || Unsigned: sampai 4294967295
  • Float => +/- 3.4e +/- 38

Explain these: {auto,const,static,register}

Auto
Syntax auto digunakan untuk membuat sebuah variabel lokal. Auto juga digunakan untuk membuat sebuah variabel sementara/temporer, yang di hanya digunakan di dalam blok dimana variabel itu dibuat. Syntax auto sebenarnya bersifat opsional, karena setiap variabel lokal selalu bersifat auto secara default ketika di buat.
Contoh dari penggunaan syntax auto:

#include <stdio.h>

 int main(void)

 {

    for(i=1; i<=5; i++)

    {        

    if (getch() == ’y’)

        {

            auto int k;

            for (k=0; k<’y’; k++)

                printf("%d ", k);

            break;

           }

 }

    return 0;

 } 
Dalam contoh diatas variabel k hanya bisa digunakan didalam blok if, program akan error ketika variabel k digunakan di luar blok. 

Const
Syntax const menunjukan bahwa suatu variabel nilainya adalah tetap dan tidak bisa diubah. Untuk membuat sebuah variabel dengan type const kita harus menentukan nilai awal terlebih dahulu.
Contoh pendeklrasian const : const int pass = 65;

Static
Type data modifier static digunakan untuk menyuruh compiler agar membuat tempat penyimpanan yang permanen untuk variabel lokal yang mendahuluinya. Hal ini memungkinkan suatu variabel yang telah ditentukan mempertahankan nilainya antara panggilan fungsi. Kata kunci static dapat diterapkan untuk kedua definisi data dan fungsi yaitu:
1.static data-definition;
2.static function-definition;
Contoh penggunaan: static int last_time;

Static dapat  juga di pakai sebagai variable global yang terbatas dengan skop pada file yang di deklarasikan.

Register
Register adalah modifier tempat penyimpanan yang dapat digunakan untuk meminta agar suatu pemasukan pada variabel dioptimalkan kecepatannya. Secara tradisional, register hanya dapat dipakai  pada variabel integer dan karakter, register tersebut menyebabkan variabel-variabel tersebut disimpan dalam register CPU sebagai pengganti dari ditempatkannya pada memori. Standar ANSIC telah diperluas definisinya agar dapat memasukkan semua tipe data. Namun demikian data selain integer dan karakter, biasanya tak dapat disimpan dalam CPU register. Syntax register hanya dapat digunakan pada variabel lokal.

Contoh penggunaan: register int p;

Explain typical C program development environment

Pada umumnya system C terdiri menjadi beberapa bagian: pengembangan program, bahasa pemrograman, dan standard library C. Program C harus melewati 6 tahap dahulu sebelum bisa di eksekusi. Yaitu edit, preprocces, compile, link, load, dan execute. 

Tahap 1: Creating a program
Yaitu tahap pengeditan file itu sendiri. Di tahap ini kita membutuhkan program editor, 2 editor yang banyak digunakan di system Linux adalah vi dan emacs. Software packages seperti Eclips dan Microsoft Visual Studio berintegrasi langsung dengan pemrograman. Anda mengetikanan program C, mengkoreksi jika perlu, lalu menyimpannya ke perangkat penyimpanan sekunder seperti harddisk. Program C harus di simpan dengan ekstensi .c agar bisa di buka di program editor. Beberapa editor yang bisa kita gunakan antara lain Dev C++, Borland, dll.

Contoh pembuatan (creating) sebuah program:
















Tahap 2 dan 3: Preprocessing and Compiling a C Program
Di tahap 2, anda memberikan perintah untuk mengkompile program, lalu compiler menerjemahkan kode program ke dalam bahasa mesin. Di program C preprocessor akan secara otomatis di eksekusi sebelum tahap penerjemahan dimulai. C preprocessor akan mematuhi perintah khusus yang disebut preprocessor directives, yang menunjukan ada sebuah manipulasi tertentu yang dilakukan sebelum di kompile. Manipulasi ini biasanya terdiri dari peng-include-an file lain ke dalam file untuk di kompile dan melakukan beberapa pergantian teks. Di tahap ini , compiler akan menerjemahkan ke dalam bahasa mesin.

Sebagai contoh, untuk meng-compile sebuah program menggunakan Dev C++ kita bisa menggunakan shortcut F9, setelah kita menyimpan file tersebut dengan format .c. 

Tahap 4: Linking
Tahap ke 4 disebut linking. Program C biasanya berisi refrensi dari fungsi yang di definisikan di tempat lain, seperti standard libraries atau di privat libraries dari grup yang programmer kerjakan di proyek tertentu. Kode ini biasanya “berlubang” karena ada bagian yang hilang.Linker menyambungkan kode objek dengan kode untuk fungsi yang hilang untuk memproduksi executable image (tanpa bagian yang hilang).  Di system Linux, perintah untuk mengkompile atau menghubungkan program disebuat cc atau gcc. 

Ini adalah contoh alur proses linking:

















Tahap 5: Loading
Sebelum program bisa di eksekusi, program harus di tempatkan di memory terlebih dahulu. Ini sudah dilakukan oleh loader, yang memindahkannya ke dalam memory. Komponen tambahan dari shared libraries yang menyupport program juga ikut di muat.

Tahap 6: Execution
Komputer di bawah kendali CPU, program akan di eksekusi waktu itu juga. Untuk memuat dan mengeksekusi program di system Linux, tipe ./a.out di linux prompt  dan tekan enter.


Masalah yang mungkin terjadi saat eksekusi program:
Program tidak selalu work di percobaan pertama. Setiap tahap bisa gagal karena beberapa errors yang akan kita diskusikan. Sebagai contoh, ketika program di perintahkan untuk membagi angka dengan 0. Ini akan menyebabkan komputer akan menampilkan pesan error, anda harus kembali mengedit program, dan membenarkan yang perlu untuk memastikan bahwa program bisa berjalan dengan baik.

Hampir semua rogram C melakukan input dan output data. Program C akan mengambil input mereka dari stdin (standard input C), biasanya menggunakan keyboard, tapi stdin juga bisa terkoneksi dengan perangkat lain. Untuk output, C menggunakan stdout (standard output C), yang biasanya layar komputer, tapi stdout juga bisa terkoneksi dengan perangkat lain. Ketika kita berkata program menampilkan hasil, biasanya kita mengartikannya bahwa output akan tampil di layar komputer, data bisa ditampilkan di perangkat lain seperti printer dan disk. Ada juga standard error C, yaitu stderr. Stderr digunakan untuk menampilkan pesan error.

Minggu, 23 Maret 2014

Exercise 3.46 (Deitel: C How to Program 6th Edition)

a) Write a program that reads a nonnegative integer and computes and prints its factorial.
#include <stdio.h>

int main(){

    int fact, result = 1, i;

    printf("Masukan angka non negative: ");

    scanf("%d", &fact);

    if(fact>0){

       for(i=fact; i>=1; i--){

          result *= i;

       }

       printf("Hasil dari %d! adalah %d.\n", fact, result);

    }

    system("pause");

}

Exercise 3.42 (Deitel: C How to Program 6th Edition)

Write a program that reads the radius of a circle (as a float value) and computes and prints the diameter, the circumference and the area. Use the value 3.14159 for π.

C Program: 
#include <stdio.h>
 

int main(){

    float jari, diameter, keliling, luas;

    printf("Masukan jari-jari: ");

    scanf("%f", &jari);

    diameter = 2*jari;

    keliling = 3.14159*2*jari;

    luas = 3.14159*jari*jari;

    printf("Diameter\t: %.2f\n", diameter);

    printf("Keliling\t: %.2f\n", keliling);

    printf("Luas\t: %.2f\n", luas);

    system("pause");

    return 0;

}
Output: 

Exercise 3.38 - 3.40 (Deitel: C How to Program 6th Edition)

3.38 

Write a program that prints 100 asterisks, one at a time. After every tenth asterisk, your program should print a newline character. [Hint: Count from 1 to 100. Use the remainder operator to recognize each time the counter reaches a multiple of 10.]

C Program:
#include <stdio.h> 
int main(){
    int a, b;
    for(a=0; a<=10; a++){

       for(b=0; b<=10; b++) {
          printf("*");       }
       printf("\n");

    }

    system("pause");

}
Output:













3.39 (Counting 7s)

Write a program that reads an integer and determines and prints how many digits in the integer are 7s.

C Program:
#include <stdio.h>

int main(){

    int input, temp, sisa = 0, seven = 0;

    printf("Masukan angka: ");

    scanf("%d", &input);

    temp=input;

    while(temp!=0){

       sisa=temp%10;

       if(sisa==7) {seven++;}

       temp/=10;

    }

    printf("Jumlah angka 7 ada %d angka.\n", seven);

    system("pause");

}
Output:










3.40 (Checkerboard Pattern of Asterisks)

Write a program that prints 100 asterisks, one at a time.


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


int main()

{

int side =8;

int row;

int mod;
while( side >=1) {
row =8;

mod = side %2;


while( row >=1) {

       if( mod !=0) {

printf(" ");
mod =0;
}

printf("* ");

--row;

}

printf("\n");

--side;

}

system ("PAUSE");
Output:

Exercise 3.34, 3.35, 3.36 (Deitel: C How to Program 6th Edition)

3.34 (Hollow Square of Asterisks) 

Modify the program you wrote in Exercise 3.33 so that it prints a hollow square. 

C Program:
#include <stdio.h>
int main(){

    int size, i, j;

    size = 5;

    for(i=1; i<=size; i++){

       if(i==1 || i==size){

          for(j=1; j<=size; j++){

             printf("*");

          }

       }

       else{

          for(j=1; j<=size; j++) {

             if(j==1 || j==size) printf("*"); else printf(" ");

          }

       }

       printf("\n");

    }

    system("pause");

}
Output:







3.35 (Palindrome Tester)

A palindrome is a number or a text phrase that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write a program that reads in a five-digit integer and determines whether or not it’s a palindrome. [Hint: Use the division and remainder operators to separate the number into its individual digits.]

C Program: 
#include <stdio.h>
int main()

{

  int n, reverse=0, rem,temp;

  printf("Enter an integer: ");

  scanf("%d", &n);

  temp=n;

  while(temp!=0)

  {
     rem=temp%10;
     reverse=reverse*10+rem;

     temp/=10;

  }

/* Checking if number entered by user and it's reverse number is equal. */

  if(reverse==n)

      printf("%d is a palindrome.",n);

  else

      printf("%d is not a palindrome.",n);

      system("pause");

  return 0;

}
Output:








3.36 (Printing the Decimal Equivalent of a Binary Number)

Input an integer containing only 0s and 1s (i.e., a “binary” integer) and print its decimal equivalent. [Hint: Use the remainder and division operators to pick off the “binary” number’s digits one at a time from right to left. Just as in the decimal number system, in which the rightmost digit has a positional value of 1, and the next digit left has a positional value of 10, then 100, then 1000, and so on, in the binary number system the rightmost digit has a positional value of 1, the next digit left has a positional value of 2, then 4, then 8, and so on. Thus the decimal number 234 can be interpreted as 4 * 1 + 3 * 10 + 2 * 100. The decimal equivalent of binary 1101 is 1 * 1 + 0 * 2 + 1 * 4 + 1 * 8 or 1 + 0 + 4 + 8 or 13.]

C Program: 
#include <stdio.h> int binary_conversion(int);int main(){   int num, bin;   printf("Enter a decimal number: ");   scanf("%d", &num);   bin = binary_conversion(num);   printf("The binary equivalent of %d is %d\n", num, bin);   system("pause");} int binary_conversion(int num){    if (num == 0)    { return 0; }    else    { return (num % 2) + 10 * binary_conversion(num / 2);  }}
Output:

Exercise 3.29 & 3.30 (Deitel: C How to Program 6th Edition)

3.29 What does the following program print?

 #include <stdio.h>

 int main( void )
 {
 int count = 1; /* initialize count */


 while ( count <= 10 ) { /* loop 10 times */

 /* output line of text */
 printf( "%s\n", count % 2 ? "****" : "++++++++" );

 count++; /* increment count */

 } /* end while */

 system("pause");

 return 0; /* indicate program ended successfully */

 } /* end function main */
Output:












3.30 What does the following program print?



 #include <stdio.h>

 int main( void )

 {

 int row = 10; /* initialize row */

 int column; /* define column */


 while ( row >= 1 ) { /* loop until row < 1 */

 column = 1; /* set column to 1 as iteration begins */


 while ( column <= 10 ) { /* loop 10 times */

 printf( "%s", row % 2 ? "<": ">" ); /* output */

 column++; /* increment column */

 } /* end inner while */

 row--; /* decrement row */
 printf( "\n" ); /* begin new output line */
 } /* end outer while */
 system("pause");

 return 0; /* indicate program ended successfully */

 } /* end function main */

Output:

Exercise 3.17 - 3.21 (Deitel: C How to Program 6th Edition)

3.17

(Gas Mileage) Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. Develop a program that will input the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After proccessing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls.

C program:
#include <stdio.h> 
int main(){

    int miles, miles1;

    float gallon, gallon1, average, average_total;

    miles = 0;

    gallon = 0;

    printf("Enter the gallons used (-1 to ends): ");

    scanf("%f", &gallon1);

    while(gallon1 != -1){

         gallon += gallon1;

         printf("Enter the miles driven: ");

         scanf("%d", &miles1);

         miles += miles1;

         average = miles1/gallon1;

         printf("The miles/gallon for this tank was %f\n\n", average);

         average_total = miles/gallon;

         printf("Enter the gallons used (-1 to ends): ");

         scanf("%f", &gallon1);

    }

    printf("\nThe overall average was %f\n", average_total);

    system("pause");

}
 Output:

3.18

(Credit Limit Calculator) Develop a C program that will determine if a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:
a) Account number
b) Balance at the beginning of the month
c) Total of all items charged by this customer this month
d) Total of all credits applied to this customer's account this month
e) Allowed credit limit
The program should input each of these facts, calculate the new balance (= beginning balance + charges – credits), and determine if the new balance exceeds the customer's credit limit. For those customers whose credit limit is exceeded, the program should display the costumer's account number,  credit limit, new balance,  and the message "Credit limit exceeded".

C Program:
#include <stdio.h>
int main(){

    int ac_number;

    float beginning, charge, credit, credit_limit, new_balance;

    printf("Enter Account Number: ");

    scanf("%d", &ac_number);

    while(ac_number!=-1){

         printf("Enter beginning balance: ");

         scanf("%f", &beginning);

         printf("Enter total charges: ");

         scanf("%f", &charge);

         printf("Enter total credits: ");

         scanf("%f", &credit);

         printf("Enter credit limit: ");

         scanf("%f", &credit_limit);

         new_balance = beginning + charge - credit;

         if(new_balance > credit_limit){

            printf("Account :\t%d\n", ac_number);

            printf("Credit limit :\t%.2f\n", credit_limit);

            printf("Balance :\t%.2f\n", new_balance);

            printf("Credit Limit Excedeed.\n");

         }

         printf("\n");

         printf("Enter Account Number: ");

         scanf("%d", &ac_number);

    }

    system("pause");
}
Output:

3.19

(Sales Commission Calculator) One large chemical company pays its salespeople on a comission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who selss $5000 worth of chemicals in a week recieves $200 plus 9% of $5000, or total of $650. Develop a program that will input each salesperson's earnings.

C Program:
#include <stdio.h>
 

int main(){

    float sell, total;

    printf("Enter sales in dollars (-1 to end): ");

    scanf("%f", &sell);

    while(sell != -1){

         total = 200 + (sell*9/100);

         printf("Salary is : %.2f\n\n", total);

         printf("Enter sales in dollars (-1 to end): ");

         scanf("%f", &sell);

    }

    system("pause");

}
Output:

3.20

(Interest Calculator) The simple interest on a loan is calculated by the formula: 
interest = principal * rate * days / 365;
The preceding formula assumes that rate is the annual interest rate, and therefore includes the division by 365 (days). Develop a program that will input principal, rate and days for several loans, and will calculate and display the simple interest for each loan, using the preceding formula.

C Program:
#include <stdio.h>
 

int main(){

    float interest, principal, rate;

    int days;

    printf("Enter loan principal (-1 to end): ");

    scanf("%f", &principal);

    while(principal != -1){

         printf("Enter interest rate: ");

         scanf("%f", &rate);

         printf("Enter term of the loan in days: ");

         scanf("%d", &days);

         interest = principal*rate*days/365;

         printf("The interest charges is: %.2f\n\n", interest);

         printf("Enter loan principal (-1 to end): ");

         scanf("%f", &principal);

    }

    system("pause");

}
Output:

3.21

(Salary Calculator) Develop a program that will determine the gross pay for each of several employees. The company pays “straight time” for the first 40 hours worked by each employee and pays “time-and-a-half” for all hours worked in excess of 40 hours. You're given a list of the employees of the company, the number of hours employee worked last week and the hourly rate of each employee. Your program should input this information for each employee, and should determine and display the employee's gross pay.

C Program:
#include <stdio.h>
 

int main(){

    int work, normal, overtime;

    float hourly, salary;

    printf("Enter # of hours worked: ");

    scanf("%d", &work);

    while(work != -1){

         printf("Enter the hourly rate of the worker ($00.00): ");

         scanf("%f", &hourly);

         if(work<=40){

            normal = work*hourly;

            overtime = 0;

         }

         else{

            normal = 40*hourly;

            overtime = (work-40)*(hourly*3/2);

         }

         salary = normal + overtime;

         printf("Salary is: %.2f\n\n", salary);

         printf("Enter # of hours worked: ");

         scanf("%d", &work);

    }

    system("pause");

}
Output:

Exercise 3.14 (Deitel: C How to Program 6th Edition)

Write a single pseudocode statement that indicates each of the following:
a) Display the message "Enter two numbers".
b) Assign the sum of variables x, y, and z to variable p.
c) The following condition is to be tested in an if…else selection statement: The current
value of variable m is greater than twice the current value of variable v.
d) Obtain values for variables s, r, and t from the keyboard.

ANSWER:
a)  printf(“Enter two numbers”);
b)  p = x+y+z;
c)  if(m>2v)
d)  printf(“Masukan nilai s:”);
     scanf(“%d”, &s);
     printf(“Masukan nilai r:”);
     scanf(“%d”, &r);
     printf(“Masukan nilai t:”);

     scanf(“%d”, &t);

Exercise 3.13 (Deitel: C How to Program 6th Edition)

What does the following program print?
1 #include <stdio.h>
2

3 int main( void )

4 {

5 int x = 1, total = 0, y;

6

7 while ( x <= 10 ) {

8 y = x * x;

9 printf( "%d\n", y );

10 total += y;

11 ++x;

12 } /* end while */

13

14 printf("Total is %d\n", total);

15 return 0;

16 } /* end main */
Output:

Exercise 3.11 (Deitel: C How to Program 6th Edition)

Identify and correct the errors in each of the following. [Note: There may be more than one error in each piece of code.]

a) if ( age >= 65 );
     printf( "Age is greater than or equal to 65\n" );
        else
     printf( "Age is less than 65\n" );
Kesalahan: tanda titik koma (;) setelah “if ( age >= 65 )” seharusnya dihilangkan.

Correct:
if ( age >= 65 )
     printf( "Age is greater than or equal to 65\n" );
        else

     printf( "Age is less than 65\n" );

b) int x = 1, total;
     while ( x <= 10 ) {
         total += x;
         ++x;
     }    
     Kesalahan : variable total harus mempunyai nilai awal untuk operasi menggunakan “+=”

     Correct:
     int x = 1, total = 0;
     while ( x <= 10 ) {
        total += x;
        ++x;
      }

c) While ( x <= 100 )
        total += x;
        ++x;
     Kesalahan: 
     - Nilai awal dari variable x dan total harus di deklarasikan terlebih dahulu untuk perulangan.
     - Perulangan while tidak boleh di awali dengan huruf kapital, karena pemrograman C bersifat case sensitive. 
     - Jika ada 2 statement yang ingin dilakukan di dalam perulangan while, harus di tandai didalam sebuah blok.

     Correct:
     int x = 1, total = 0;
     while ( x <= 100 ){
        total += x;
        ++x;
     }

d) while ( y > 0 ) {
      printf( "%d\n", y );
      ++y;
     }  
     Kesalahan: 
     - Nilai dan type dari variable y harus di deklarasikan terlebih dahulu, karena untuk menampilkan nilai dari variable y dengan perintah “printf” harus diketahui type dari variable tersebut.

     Correct:
     int y = -10;
     while ( y > 0 ) {
        printf( "%d\n", y );
        ++y;
     }

Sabtu, 15 Maret 2014

Operators in C program

Assignment operators

Ada beberapa operator yang bisa kita gunakan di dalam melakukan perhitungan di dalam program C. Beberapa operator biner yang sering digunakan adalah +, -, *, / or %. Dibawah ini adalah contoh-contoh penggunaan operator tersebut:


Increment and Decrement Operator

Di dalam program C juga disediakan operator yang disebut increment operator dan decrement operator. Sebagai contoh, jika sebuah variable di C ingin menambahkan nilai 1 lebih baik jika kita menggunakan c++ daripada menggunakan c = c+1 atau c+=1, begitu juga untuk penurunan nilai variable.


Perbedaan penggunaan ++a dan a++ adalah waktu penambahan. Bisa kita lihat di contoh di bawah ini:
int main (){
int c=5;

printf("Nilai c ketika printf dijalankan adalah %d", ++c);

}
Hasil: Nilai c ketika printf dijalankan adalah 6

int main (){
int c=5;

printf("Nilai c ketika printf dijalankan adalah %d", c++);

}
Hasil: Nilai c ketika printf dijalankan adalah 5