Posts

Stack Memory

Image
  Stack Memory Stack is a linear data structure that follows the LIFO (Last-In-First-Out) principle. The stack is managed by the CPU, there is no ability to modify it. Variables are allocated and freed automatically. The stack it not limitless – most have an upper bound. The stack grows and shrinks as variables are created and destroyed Stack variables only exist whilst the function that created them exists       Stack of Books                                                                  Stack of Coins       

Important Links for Coding Interview Preparation

10 important links to practice and study for coding interviews : 1.  patterns to ace any coding interview:  https://lnkd.in/gBu9uZtz 2. Backtracking solution for 10 popular problems:  https://lnkd.in/gjpC9MCC 3. Dynamic Programming patterns for beginners:  https://lnkd.in/gevrxmmy 4. All Graph algorithms in one place:  https://lnkd.in/g2xdz7TY 5. When to use two pointers?:  https://lnkd.in/gqzEDmf6 6. Sliding Window algorithm made easy:  https://lnkd.in/gnDS8sJn 7. Ultimate Binary Search guide:  https://lnkd.in/gg_BB6ik 8. How to solve Linked List problems?:  https://lnkd.in/gp7FgTGx 9. Comprehensive Data Structure and Algorithm study guide:  https://lnkd.in/gcUnWavF 10. How to effectively use Leetcode:  https://lnkd.in/gEuRT4ik

Data Types in C

Data Types in C Primitive Data Types in C: 1. int 2. float 3. char 4. double 5. void Derived Data Types in C: 1. array 2. pointer 3. function User-Defined Data Types in C: 1. structure 2. union 3. enum #include < stdio.h > #include < stdbool.h > // extern variable declaration extern int x; int main () { int age = 30 ; char name [] = " Embedded " ; float average = 66.78 ; char gender = ' M ' ; bool result = true ; printf ( "extern integer Data : %d \n " ,x); printf ( "Integer Data : %d \n " , age ); printf ( "String Data : %s \n " , name ); printf ( "Float Data : %f \n " , average ); printf ( "Character Data : %c \n " , gender ); printf ( "Boolean Data in integer form : %d \n " , result ); printf ( " size of int is = %u \n " , sizeof ( int )); printf ( " size of char is= %u \n " , sizeof ( char )); printf ( ...

Reverse a string in c

 Reverse a string in c : #include < stdio.h > // standard input/output header file #include < string.h > // header file for string int stringLen ( char * str ) { int len = 0 ; for ( int i = 0 ; str [ i ]!= ' \0 ' ; i ++) { len ++; } return len ; } int main () { char str [ 100 ] = " ABC " ; char rev [ 100 ]; int strLength = stringLen ( str ); int j = 0 ; for ( int i = strLength - 1 ; i >= 0 ; i --) { rev [ j ++] = str [ i ]; } rev [ j ] = ' \0 ' ; printf ( " Reverse String is = %s " , rev ); printf ( " \n " ); return 0 ; } Related Posts :  basic-input/output-c-program Check a Prime Number Array in C Swap 2 Numbers Loops in C Data Types in C

Compare 2 Strings in C

Compare two strings in C : #include < stdio.h > #include < string.h > #include < stdbool.h > int main () { char str1 [] = " ABC " ; char str2 [] = " ABC " ; bool res ; int i = 0 ; while ( str1 [ i ] != ' \0 ' && str2 [ i ] != ' \0 ' ) { if ( str1 [ i ] == str2 [ i ]) res = false ; else res = true ; i ++; } printf ( " %d \n " , res ); return 0 ; } Related Posts :  basic-input/output-c-program Check a Prime Number Array in C Swap 2 Numbers Loops in C Reverse String in C

Swap 2 Numbers in C

1. Swap 2 Numbers in C without using extra space or variable  #include < stdio.h > int main () { int a , b ; printf ( " Enter value of a and b " ); scanf ( " %d %d " , & a , & b ); printf ( " a and b before swap is = %d and %d \n " , a , b ); a = a + b ; b = a - b ; a = a - b ; printf ( " a and b after swap is = %d and %d \n " , a , b ); return 0 ; } 2. Swap 2 Numbers in C using extra variable #include < stdio.h > int main () { int a , b ; printf ( " Enter value of a and b " ); scanf ( " %d %d " , & a , & b ); printf ( " a and b before swap is = %d and %d \n " , a , b ); int c ; // temporary variable c = a ; a = b ; b = c ; printf ( " a and b after swap is = %d and %d \n " , a , b ); return 0 ; } Related Posts :  basic-input/output-c-program Array in C Check a Prime Number Loop...

Control structure in C

In C programming, loops are used to execute a block of code repeatedly as long as a certain condition is met. There are three main types of loops in C: for loop while loop do-while loop 1. for Loop : The for loop is commonly used when you know beforehand how many times you want to execute a block of code. It consists of three parts: initialization, condition, and increment/decrement. Example :-   #include < stdio.h > int main () { int i = 0 ; for ( i = 0 ; i < 10 ; i ++) { printf ( " Value of i is = %d \n " , i ); } for ( i = 10 ; i > 0 ; i --) { printf ( " Value of i is = %d \n " , i ); } return 0 ; } nested-for Loop : #include < stdio.h > int main () { int n ; printf ( " Enter the count number to print table \n " ); scanf ( " %d " ,& n ); printf ( " Entered number is = %d \n " , n ); for ( int i = 1 ; i <= n ; i ++) { for ( i...