Posts

Showing posts from July, 2022

#8 | Pointers | Write a program to print the string character-by-character using pointers and find the length of a string.

Image
  YouTube Video :-  Question :-  Write a program to print the string character-by-character using pointers and find the length of a string.  Code :- /* Write a program to print the string character-by-character using pointers and find the length of a string. */ #include <stdio.h> void main() {     // declaring variables     char str[ 50 ];     char *s;     int len= 0 ;     // Collect String From user     printf( "Enter any String :- " );     scanf( "%s" ,str);     // Assign the memory address to character pointer     s = str;     //print string character by character     while (*s != '\0' )     {         // *s is use to take the value that is stored         // in given memory address         printf( "%c" ,*s);         len++;         s++;     }     printf( "\nLength of our String = %d" ,len);     } Description :- - In this Program we have to use character pointers. - We have to declare two types of character variables :- - The

#7 | Pointers | Write a program to swap two numbers using call by reference and user defined function.

Image
    YouTube Video :-  Question :-  Write a program to swap two numbers using call by reference and user defined function. Code :- //7. Write a program to swap two numbers using call by reference and user defined function. #include <stdio.h> void swap( int *, int *); void main() {     int a,b;     printf( "Enter The Value Of a : " );     scanf( "%d" ,&a);         printf( "Enter The Value Of b : " );     scanf( "%d" ,&b);     printf( "\n\nBefore Swapping :\n" );     printf( "a = %d\n" ,a);     printf( "b = %d" ,b);     swap(&a,&b); } void swap( int *p, int *q) {     int temp;     temp = *p;     *p = *q;     *q = temp;     printf( "\n\nAfter Swapping : \n" );     printf( "a = %d\n" ,*p);     printf( "b = %d" ,*q); } Description :- In this Program we have to swap two numbers using Call by Reference. Call By reference means, we have to give memory address to anoth