Bubble Sort using Call by Reference (Pointers) C Program

In one of our previous posts we already discussed about Bubble Sort algorithm and how to implement it in C programming. In this post we will discuss about bubble sort using call by reference method. In other words we will implement the bubble sort algorithm using pointers i.e call by reference. [js] #include <stdio.h> #define SIZE 10 void bubbleSort(int * const array, const int size); void swap(int *element1Ptr, int *element2Ptr); int main(void){ int arr[SIZE] = {2, 3, 9, 4, 1, 5, 7, 12, 18, 15}; printf("Original array valuesnn"); for(int i=0; i<SIZE; i++){ printf("%dn", arr[i]); } bubbleSort(arr, SIZE); printf("nnSorted array valuesnn");...
forward

Constant Pointer vs Pointer to Constant C Program

In previous post we discussed about pointers, how to define and use pointers. In this post we will learn what's the difference between constant pointer and pointer to constant. If we define a pointer as constant then we cannot modify its memory address. For example if we assigned the memory address of a variable 'a' to the pointer 'ptr'. Now if we try to assign the address of the variable 'b' to the pointer 'ptr' then compiler will throw an error message. This means that we cannot change/modify the address assigned to the constant pointer but we can modify/change the...
forward

Pointers in C Programming – Code Example

In previous posts we concluded the arrays topic. In next 2-3 posts we will discuss about pointers with some code examples. Pointers are used to store memory address of variables or arrays. In following simple program we created a pointer named as countPtr and a variable named as count. Then we assigned the address of the variable count to the pointer countPtr. Now by using that pointer we can get the memory address of the variable count as well as the value of the variable count. [js] #include <stdio.h> int main(void){ int count = 5; int *countPtr; countPtr = &count; printf("Address...
forward