Type data pada bahasa C++


Data merupakan suatu nilai yang bisa dinyatakan dalam bentuk konstanta atau variabel. Konstanta menyatakan nilai yang tetap, sedangkan variabel menyatakan nilai yang dapat diubah-ubah selama eksekusi berlangsung,

Data berdasarkan jenisnya dapat dibagi menjadi lima kelompok, yang dinamakan sebagai tipe data dasar. Kelima tipe data dasar adalah:

  • Bilangan bulat (integer)
  • Bilangan real presisi-tunggal
  • Bilangan real presisi-ganda
  • Karakter
  • Tak-bertipe (void), keterangan lebih lanjut tentang void dijelaskan dalam Bab V.


Kata-kunci yang berkaitan dengan tipe data dasar secara berurutan di antaranya adalah int (short int, long int, signed int dan unsigned int), float, double, dan char.

Tabel 2-1 memberikan informasi mengenai ukuran memori yang diperlukan dan kawasan dari masing-masing tipe data dasar.

Tabel 2-1. Ukuran memori untuk tipe data

Tipe          Total bit                Kawasan                                   Keterangan

char                8             -128 s/d 127                                karakter

int                32             -2147483648 s/d 2147483647    bilangan integer

float              32             1.7E-38 s/d 3.4E+38                    bilangan real presisi-tunggal

double          64             2.2E-308 s/d 1.7E+308                bilangan real presisi-ganda

Untuk tipe data short int, long int, signed int dan unsigned int, maka ukuran memori yang diperlukan serta kawasan dari masint-masing tipe data adalah sebagai berikut :

Tipe                Total bit                Kawasan                                   Keterangan

 

short int            16             -32768 s/d 32767                             short integer

long int              32            -2147483648 s/d 2147483647       long integer

signed int          32            -2147483648 s/d 2147483647       biasa disingkat dengan int 

unsigned int     32            0 s/d 4294967295                            bilangan int tak bertanda         

Catatan :

§  Ukuran dan kawasan dari masing-masing tipe data adalah bergantung pada jenis mesin yang digunakan (misalnya mesin 16 bit bisa jadi memberikan hasil berbeda dengan mesin 32 bit).

2.2  Variabel

2.2.1 Aturan Pendefinisan Variabel

Aturan penulisan pengenal untuk sebuah variabel, konstanta atau fungsi yang didefinisikan oleh pemrogram adalah sebagai berikut :

§  Pengenal harus diawali dengan huruf (A..Z, a..z) atau karakter garis bawah ( _ ).

§  Selanjutnya dapat berupa huruf, digit (0..9) atau karakter garis bawah atau tanda dollar ($).

§  Panjang pengenal boleh lebih dari 31 karakter, tetapi hanya 31 karakter pertama yang akan dianggap berarti.

§  Pengenal tidak boleh menggunakan nama yang tergolong sebagai kata-kata cadangan (reserved words) seperti int, if, while dan sebagainya.

2.2.2 Mendeklarasikan Variabel

Variabel digunakan dalam program untuk menyimpan suatu nilai, dan nilai yang ada padanya dapat diubah-ubah selama eksekusi program berlangsung. Variabel yang akan digunakan dalam program haruslah dideklarasikan terlebih dahulu. Pengertian deklarasi di sini berarti memesan memori dan menentukan jenis data yang bisa disimpan di dalamnya.

 

Bentuk umum deklarasi variabel:

tipe daftar-variabel;

 

Pada pendeklarasian varibel, daftar-variabel dapat berupa sebuah variabel atau beberapa variabel yang dipisahkan dengan koma. Contoh:

     int var_bulat1;

     float var_pecahan1, var_pecahan2;

 

 

2.2.3 Memberikan Nilai ke Variabel

Untuk memberikan nilai ke variabel yang telah dideklarasikan, maka bentuk umum pernyataan yang digunakan adalah :

nama_variabel = nilai;

 

 

Contoh:

     int var_bulat = 10;

     double var_pecahan = 10.5;

 

 

2.2.4 Inisialisasi Variabel

Adakalanya dalam penulisan program, setelah dideklarasikan, variabel langsung diberi nilai awal. Sebagai contoh yaitu variabel nilai :

 

            int nilai;

nilai = 10;

 

Dua  pernyataan di atas sebenarnya dapat disingkat melalui pendeklarasian yang disertai penugasan nilai, sebagai berikut :

 

            int nilai= 10;

 

Cara seperti ini banyak dipakai dalam program C, di samping menghemat penulisan pernyataan, juga lebih memberikan kejelasan, khususnya untuk variabel yang perlu diberi nilai awal (diinisialisasi).

 

2.3 Konstanta

            Konstanta menyatakan nilai yang tetap. Berbeda dengan variabel, suatu konstanta tidak dideklarasikan. Namun seperti halnya variabel, konstanta juga memiliki tipe. Penulisan konstanta mempunyai aturan tersendiri, sesuai dengan tipe masing-masing.

§  Konstanta karakter misalnya ditulis dengan diawali dan diakhiri dengan tanda petik tunggal, contohnya : ‘A’ dan ‘@’.

§  Konstanta integer ditulis dengan tanda mengandung pemisah ribuan dan tak mengandung bagian pecahan, contohnya : –1 dan 32767.

§  Konstanta real (float dan double) bisa mengandung pecahan (dengan tanda berupa titik) dan nilainya bisa ditulis dalam bentuk eksponensial (menggunakan tanda e), contohnya : 27.5f (untuk tipe float) atau 27.5 (untuk tipe double) dan 2.1e+5 (maksudnya 2,1 x 105 ).

§  Konstanta string merupakan deretan karakter yang diawali dan diakhiri dengan tanda petik-ganda (), contohnya :“Pemrograman Dasar C”.

 

 

2.4 Operator

            Operator merupakan simbol atau karakter yang biasa dilibatkan dalam program untuk melakukan sesuatu operasi atau manipulasi, seperti menjumlahkan dua buah nilai, memberikan nilai ke suatu variabel, membandingkan kesamaan dua buah nilai.  Sebagian operator C tergolong sebagai operator binary, yaitu operator yang dikenakan terhadap dua buah nilai (operand). Contoh :

            a + b

 

Simbol + merupakan operator untuk melakukan operasi penjumlahan dari kedua operand-nya (yaitu a dan b). Karena operator penjumlahan melibatkan dua operator ini tergolong sebagai operator binary.

 

            -c

 

Simbol (minus) juga merupakan operator. Simbol ini termasuk sebagai operator unary, yaitu operator yang hanya memiliki sebuah operand (yaitu c pada contoh ini).

 

 

2.4.1. Operator Aritmatika

§  Operator untuk operasi aritmatika yang tergolong sebagai operator binary adalah :

*          perkalian

/          pembagian

%          sisa pembagian

+          penjumlahan

          pengurangan

§  Adapun operator yang tergolong sebagai operator unary.

                     tanda minus

            +          tanda plus

            Contoh pemakaian operator aritmatika misalnya untuk memperoleh nilai diskriminan dari suatu persamaan kuadrat :  D = b2 – 4ac

 

/* File program : diskrim.c

 Menghitung diskriminan pers kuadrat  ax^2 + bx + c = 0 */

# include <stdio.h>

 

main()

{

    float a,b,c,d;

    a = 3.0f;

    b = 4.0f;

    c = 7.0f;

 

    d = b*b-4*a*c;

    printf(“Diskriminan =%f\n”,d);

}

 

 

Contoh eksekusi :

 

Diskriminan = -84.000000

Operator yang telah dituliskan di atas, yang perlu diberi penjelasan lebih lanjut adalah operator sisa pembagian. Beberapa contoh berikut kiranya akan memperjelas makna dari operator ini .

·         Sisa pembagian bilangan 7 dengan 2 adalah 1 (7 % 2 à 1)

·         Sisa pembagian bilangan 6 dengan 2 adalah 0 (6 % 2 à 0)

·         Sisa pembagian bilangan 8 dengan 3 adalah 1 (8 % 3 à 2)

Kegunaan operator ini diantaranya bisa dipakai untuk menentukan suatu bilangan bulat termasuk ganjil atau genap, berdasarkan logika : “Jika bilangan habis dibagi dua (sisanya nol), bilangan termasuk genap. Sebaliknya, termasuk ganjil”.

2.4.2. Operator Penurunan dan Penaikan

            Masih berkaitan dengan operasi aritmatika, C menyediakan operator yang disebut sebagai operator penaikan dan operator penurunan, yaitu :

++    operator penaikan

 operator penurunan

Operator penaikan digunakan untuk menaikkan nilai variabel sebesar satu. Penempatan operator terhadap variabel dapat dilakukan di muka atau di belakangnya, contohnya :

 

     x = x+1;

     y = y+1;

Bisa ditulis menjadi :

     ++x;

     –y;

atau :

 

            x++;

     y–;

 

bergantung pada kondisi yang dibutuhkan oleh pemrogram.  Di bawah ini adalah contoh yang akan menunjukkan perbedaan pemakaian dan hasil dari ++x dengan x++ (atau pemakaian y– dengan –-y).

/* File program : pre_post.c
Contoh penggunaan pre & post Increment operator */
 
#include <stdio.h>
 
main()
{
    int count = 0, loop;
    
    loop = ++count;  /* count=count+1; loop=count; */
    printf("loop = %d, count = %d\n", loop, count);
    
    loop = count++;  /* loop=count; count=count+1; */
    printf("loop = %d, count = %d\n", loop, count);
}
 
 
Contoh eksekusi :
 
loop = 1, count = 1
loop = 1, count = 2

2.4.3. Prioritas Operator Aritmatika

            Tabel di bawah ini  memberikan penjelasan mengenai prioritas dari masing-masing operator. Operator yang mempunyai prioritas tinggi akan diutamakan dalam hal pengerjaan dibandingkan dengan operator yang memiliki prioritas lebih rendah.

 

Normal
0

false
false
false

EN-US
X-NONE
X-NONE

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Table Normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:””;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:”Times New Roman”,”serif”;}

Prioritas                                           Operator                                                  urutan pengerjaan

Tertinggi                ( )                                       dari kiri ke kanan

!     ++    —    +    –                  dari kanan ke kiri *)

*     /     %                             dari kiri ke kanan

+     –                                   dari kiri ke kanan *)

Terendah              =     +=    -=    *=    /=    %=          dari kanan ke kiri

*)   Bentuk unary + dan unary memiliki prioritas yang lebih tinggi daripada bentuk binary + dan binary

 

Untuk tipe data short int, long int, signed int dan unsigned int, maka ukuran memori yang diperlukan serta kawasan dari masint-masing tipe data adalah sebagai berikut :

66 Comments Add yours

  1. Dillon mengatakan:

    Magnificent beat ! I would like to apprentice while you amend
    your web site, how can i subscribe for a blog website?
    The account helped me a acceptable deal. I had been tiny bit acquainted of this your
    broadcast provided bright clear concept

  2. torching.us mengatakan:

    Hello There. I discovered your blog the usage of
    msn. That is a very smartly written article.
    I’ll be sure to bookmark it and return to learn extra of your helpful information. Thank you for the post.
    I will definitely comeback.

  3. bangalore.afindia.org mengatakan:

    Hey There. I found your blog using msn. This is an extremely well written article.
    I will be sure to bookmark it and return to read more
    of your useful info. Thanks for the post. I’ll
    certainly comeback.

  4. Taj mengatakan:

    Thanks a bunch for sharing this with all of us you actually understand what you are speaking about!
    Bookmarked. Kindly additionally visit my
    web site =). We can have a hyperlink change contract between us

  5. nutritie mengatakan:

    Do you have a spam problem on this site; I also am a blogger, and I was curious about your situation; many of us have created some nice methods and we are looking to trade methods with others,
    be sure to shoot me an e-mail if interested.

  6. husa telefoane mengatakan:

    This blog was… how do you say it? Relevant!! Finally I’ve found something which helped me.
    Cheers!

  7. chicago pergola mengatakan:

    I know this web site provides quality based content and additional information, is there any other web site which presents
    these information in quality?

  8. Great blog here! Also your website loads up very fast! What
    web host are you using? Can I get your affiliate link
    to your host? I wish my web site loaded up as quickly as yours lol

  9. mancamp catering mengatakan:

    Hola! I’ve been following your weblog for a while now and finally got the bravery to go ahead and give you a shout out from Atascocita
    Tx! Just wanted to mention keep up the excellent work!

  10. I know this website provides quality dependent articles or reviews
    and additional stuff, is there any other web page which gives such data
    in quality?

  11. you are really a excellent webmaster. The website loading velocity is incredible.
    It kind of feels that you are doing any distinctive trick.
    Also, The contents are masterwork. you’ve performed a great task in this subject!

  12. I got this web page from my pal who told me on the topic of this website and now this time I am
    visiting this web page and reading very informative articles at this place.

  13. VigRX male supplement mengatakan:

    I’m gone to tell my little brother, that he should also pay a visit this blog on regular basis to obtain updated from
    most up-to-date gossip.

  14. It is in point of fact a great and useful piece
    of information. I’m happy that you just shared this useful information with us.

    Please keep us up to date like this. Thanks for
    sharing.

  15. Thank you for sharing your info. I truly appreciate your efforts and I
    am waiting for your next post thanks once again.

  16. auto rental mengatakan:

    Good post however I was wondering if you could write a litte more on this subject?
    I’d be very thankful if you could elaborate a little bit further.
    Many thanks!

  17. cars for rent mengatakan:

    An interesting discussion is definitely worth comment.
    I do believe that you need to write more on this topic, it might not be a
    taboo subject but generally people do not speak about such topics.

    To the next! Kind regards!!

  18. Nulled Scripts mengatakan:

    Truly when someone doesn’t be aware of afterward its up to other
    visitors that they will assist, so here it happens.

  19. I was very pleased to find this web site. I wanted to thank you for
    ones time for this particularly fantastic read!! I definitely enjoyed every part
    of it and I have you bookmarked to look at new stuff in your blog.

  20. lovecetera.com mengatakan:

    I’m not that much of a online reader to be honest but your blogs really nice, keep it up!
    I’ll go ahead and bookmark your website to come back later.
    Cheers

  21. armorgames.com mengatakan:

    This post will help the internet people for building up new weblog or even a weblog
    from start to end.

  22. 2innavate.com mengatakan:

    This is really interesting, You’re an overly professional blogger.

    I have joined your rss feed and look forward to
    in the hunt for extra of your excellent post. Additionally, I have shared your web site in my social networks

  23. vand struguri mengatakan:

    Hello it’s me, I am also visiting this web page regularly, this site is truly pleasant and
    the viewers are actually sharing good thoughts.

  24. mirena bleeding mengatakan:

    My spouse and I absolutely love your blog and find most of your post’s to be
    precisely what I’m looking for. Would you offer guest writers to write content available for you?
    I wouldn’t mind writing a post or elaborating on most
    of the subjects you write with regards to here.
    Again, awesome site!

  25. www.dmoz.org mengatakan:

    Woah! I’m really enjoying the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s tough to get
    that “perfect balance” between superb usability
    and visual appeal. I must say you’ve done a very good job
    with this. Also, the blog loads super fast for me on Opera.
    Exceptional Blog!

  26. Good post. I learn something totally new and challenging on websites I stumbleupon every day.
    It’s always helpful to read content from other writers and practice something from their web sites.

  27. linh kien loc nuoc mengatakan:

    Good day! I know this is kind of off topic but I was wondering which blog
    platform are you using for this website? I’m getting tired of WordPress because
    I’ve had problems with hackers and I’m looking at options for another platform.

    I would be awesome if you could point me in the direction of a good platform.

  28. entrydrivealert.com mengatakan:

    I’m pretty pleased to find this great site. I want to to thank you for your
    time due to this wonderful read!! I definitely loved every bit of it and I have you
    book-marked to check out new things on your website.

  29. Get More Information mengatakan:

    Thanks for sharing your info. I truly appreciate your efforts and
    I will be waiting for your further post thanks once again.

  30. s.unair.ac.id mengatakan:

    Link exchange is nothing else however it is simply placing the other person’s weblog link on your page
    at appropriate place and other person will also do same in support of
    you.

  31. android indonesia mengatakan:

    Hello there, You have done a great job. I will definitely digg it and personally recommend to my friends.
    I am sure they’ll be benefited from this site.

  32. Hey there! I know this is somewhat off topic but I was wondering
    which blog platform are you using for this website? I’m getting sick and tired of WordPress because I’ve had issues with hackers
    and I’m looking at alternatives for another platform.
    I would be fantastic if you could point me in the direction of a good
    platform.

  33. Winnie mengatakan:

    It’s difficult to find experienced people for this subject,
    however, you sound like you know what you’re talking about!
    Thanks

  34. What’s up, this weekend is good in support of me, because this time i am reading this wonderful educational
    paragraph here at my house.

  35. umair4101.jux.com mengatakan:

    Wonderful beat ! I would like to apprentice while you amend your
    website, how can i subscribe for a blog website?

    The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast offered bright
    clear idea

  36. Ashely mengatakan:

    Wonderful post but I was wondering if you could write a litte more on this subject?
    I’d be very thankful if you could elaborate a little
    bit further. Cheers!

  37. Hello! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to get my
    blog to rank for some targeted keywords but I’m not seeing very good gains.

    If you know of any please share. Cheers!

  38. It’s really a nice and useful piece of information. I’m glad that you shared this helpful information with us.
    Please stay us informed like this. Thanks for sharing.

  39. peixoto bikini mengatakan:

    I do not know whether it’s just me or if perhaps everybody else encountering problems with your website.

    It seems like some of the written text in your content are running
    off the screen. Can someone else please provide feedback and let me know if this is happening
    to them too? This could be a issue with my web browser because I’ve had this happen previously.

    Thank you

  40. visit this website mengatakan:

    Hi it’s me, I am also visiting this web page on a regular basis,
    this website is really pleasant and the viewers are in fact sharing fastidious thoughts.

  41. visit this site mengatakan:

    Hi i am kavin, its my first occasion to commenting anywhere, when i read this piece of writing
    i thought i could also create comment due to this brilliant article.

  42. Esperanza mengatakan:

    This paragraph is truly a good one it assists new internet viewers, who are wishing for blogging.

  43. eberjey bikini mengatakan:

    I really like looking through an article that can make men and women think.

    Also, many thanks for allowing me to comment!

  44. learn more mengatakan:

    Very nice article. I definitely love this website.
    Keep writing!

  45. Garland mengatakan:

    I am truly thankful to the holder of this web page
    who has shared this enormous piece of writing at here.

  46. I am genuinely grateful to the holder of this web site who
    has shared this impressive article at here.

  47. Good response in return of this question with real arguments
    and describing all concerning that.

  48. تنزيل العاب mengatakan:

    Today, I went to the beachfront with my children. I found a sea
    shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and
    screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is totally off topic but I had to tell someone!

  49. facebook credits hack mengatakan:

    Hi there to every one, it’s really a good for me to go to see this website, it includes useful Information.

  50. Hi there I am so excited I found your webpage, I really found you by accident,
    while I was searching on Digg for something else, Nonetheless I am here now and would just like to say kudos for a tremendous post and a all round enjoyable blog
    (I also love the theme/design), I don’t have time to read through it all at the minute but I have
    saved it and also added your RSS feeds, so when I have time I will be back to read more, Please do keep up the
    superb b.

  51. embryonic stem cells mengatakan:

    It’s actually a nice and helpful piece of
    info. I am satisfied that you simply shared this useful information with us.

    Please keep us up to date like this. Thanks for sharing.

  52. may loc nuoc ro mengatakan:

    What’s up, after reading this amazing post i am as well delighted
    to share my experience here with friends.

  53. Aline mengatakan:

    The other day, while I was at work, my sister stole my iPad and tested to see
    if it can survive a 40 foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views.
    I know this is entirely off topic but I had to share it with someone!

  54. tai jewelry website mengatakan:

    Hello there, just became alert to your blog through Google,
    and found that it is really informative. I’m gonna watch out for brussels.
    I will appreciate if you continue this in future. A
    lot of people will be benefited from your writing.
    Cheers!

  55. welkinn.com mengatakan:

    Hmm it appears like your blog ate my first comment (it was super long)
    so I guess I’ll just sum it up what I submitted and say, I’m thoroughly enjoying your blog.
    I as well am an aspiring blog writer but
    I’m still new to the whole thing. Do you have any points for novice blog
    writers? I’d really appreciate it.

  56. Driving License UK mengatakan:

    Its not my first time to pay a quick visit this website, i am browsing this web page
    dailly and get nice data from here daily.

  57. Sandra mengatakan:

    First of all I want to say terrific blog! I had a quick question in which I’d like to ask if you
    do not mind. I was curious to find out how you center yourself and clear your mind before writing.
    I’ve had a hard time clearing my mind in getting my thoughts out.
    I do take pleasure in writing but it just seems like the first 10 to 15
    minutes are lost just trying to figure out how to begin. Any recommendations
    or tips? Thanks!

  58. promovare web mengatakan:

    Hurrah! After all I got a webpage from where I know how to truly get useful data concerning my study and knowledge.

  59. publicitate online mengatakan:

    I must thank you for the efforts you have put in penning this blog.
    I am hoping to check out the same high-grade blog posts by you in the future as well.
    In fact, your creative writing abilities has motivated me to get my
    own website now😉

  60. promovare web site mengatakan:

    If some one desires to be updated with latest technologies then he must
    be visit this web site and be up to date every day.

  61. www.agelon.cn mengatakan:

    We’re a bunch of volunteers and opening a new scheme in our community.
    Your website provided us with helpful information to work on.
    You have done a formidable task and our entire group will likely be thankful to you.

  62. Nannette mengatakan:

    I just like the valuable information you supply on your articles.
    I’ll bookmark your blog and test again here frequently. I am rather sure I’ll be informed a
    lot of new stuff right right here! Best of luck for the next!

  63. Excellent post. I was checking continuously this blog and I’m impressed!
    Very useful information particularly the last part 🙂 I care for such information much. I was looking
    for this particular information for a very long time. Thank
    you and good luck.

  64. Marcella mengatakan:

    It’s very trouble-free to find out any topic on net as compared to textbooks, as
    I found this article at this web site.

  65. Leslee mengatakan:

    I’m impressed, I have to admit. Rarely do I come across a blog that’s both educative and entertaining, and let me tell you, you’ve hit the nail on the head.
    The problem is something not enough men and women are speaking intelligently about.
    I’m very happy I stumbled across this during my search for
    something relating to this.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s