Langsung ke konten utama

Unggulan

Cara Mencegah Inflasi

Pengertian Inflasi Menurut Kamus Besar Bahasa Indonesia, inflasi adalah kemerosotan nilai uang (kertas) karena banyaknya dan cepatnya uang (kertas) beredar sehingga menyebabkan naiknya harga barang-barang. Bank Indonesia  memberikan definisi, inflasi adalah kenaikan harga barang dan jasa secara umum dan terus menerus dalam jangka waktu tertentu. Sedangkan menurut Badan Pusat Statistik, inflasi adalah kecenderungan naiknya harga barang dan jasa pada umumnya yang berlangsung secara terus menerus. Inflasi adalah hal yang biasa terjadi pada negara yang sedang berkembang, yang mengalami kenaikan harga secara meluas dan simultan. Inflasi adalah gejala ekonomi, yang hampir bisa dipastikan tidak mungkin bisa dihindari. Yang bisa dilakukan oleh suatu negara adalah mengendalikannya. Jenis-Jenis Inflasi 1. Inflasi ringan Skala ringan dalam inflasi adalah yang masih dalam tingkat mudah dikendalikan. Biasanya tidak memberikan efek yang terlalu mengganggu stabilitas ekonomi suatu negara. Parameterny

Learning Pointer In C

Pointers are also variables and play a very important role in C programming language. They are used for several reasons, such as:
  • Strings
  • Dynamic memory allocation
  • Sending function arguments by reference
  • Building complicated data structures
  • Pointing to functions
  • Building special data strcutures (i.e. Tree, Tries, etc...)
And many more.

What is a pointer?

A pointer is essentially a simple integer variable which holds a memory address that points to a value, instead of holding the actual value itself.
The computer's memory is a sequential store of data, and a pointer points to a specific part of the memory. Our program can use pointers in such a way that the pointers point to a large amount of memory - depending on how much we decide to read from that point on.

Strings as pointers

We've already discussed strings, but now we can dive in a bit deeper and understand what strings in C really are (which are called C-Strings to differentiate them from other strings when mixed with C++)
The following line:
char * name = "John";
Execute Code
does three things:
  1. It allocates a local (stack) variable called name, which is a pointer to a single character.
  2. It causes the string "John" to appear somewhere in the program memory (after it is compiled and executed, of course).
  3. It initializes the name argument to point to where the J character resides at (which is followed by the rest of the string in the memory).
If we try to access the name variable as an array, it will work, and will return the ordinal value of the character J, since the name variable actually points exactly to the beginning of the string.
Since we know that the memory is sequential, we can assume that if we move ahead in the memory to the next character, we'll receive the next letter in the string, until we reach the end of the string, marked with a null terminator (the character which it's ordinal value is 0, noted as \0).

Dereferencing

Dereferencing is the act of referring to where the pointer points at, instead of the memory address. We are already using dereferencing in arrays - but we just didn't know it yet. The brackets operator - [0] for example, accesses the first item of the array. And since arrays are actually pointers, accessing the first item in the array is the same as dereferencing a pointer. Dereferencing a pointer is done using the asterisk operator *.
If we want to create an array that will point to a different variable in our stack, we can write the following code:

/* define a local variable a */
int a = 1;

/* define a pointer variable, and point it to a using the & operator */
int * pointer_to_a = &a;

printf("The value a is %d\n", a);
printf("The value of a is also %d\n", *pointer_to_a);

Execute Code
Notice that we used the & operator to point at the variable a, which we have just created.
We then referred to it using the dereferencing operator. We can also change the contents of the dereferenced variable:


int a = 1;
int * pointer_to_a = &a;

/* let's change the variable a */
a += 1;

/* we just changed the variable a again! */
*pointer_to_a += 1;

/* will print out 3 */
printf("The value of a is now %d\n", a);

Reference : http://www.learn-c.org/en/Pointers

Komentar

Postingan Populer