Important

Q1. Difference betweenn local and global variables.


BASIS FOR COMPARISONLOCAL VARIABLEGLOBAL VARIABLE
DeclarationVariables are declared inside a function.Variables are declared outside any function.
ScopeWithin a function, inside which they are declared.Throughout the program.
AccessAccessed only by the statements, inside a function in which they are declared.Accessed by any statement in the entire program.
LifeCreated when the function block is entered and destroyed upon exit.Remain in existence for the entire time your program is executing.
StorageLocal variables are stored on the stack, unless specified.Stored on a fixed location decided by a compiler.

Q2. Wap a program to search INDIA from string

LOVEINDIA and display it on screen.



#include <string.h>
#include <stdio.h>
  
int main()
{
    // Take any two strings
    char s1[] = "LOVEINDIA";
    char s2[] = "INDIA";
    char* p;
  
    // Find first occurence of s2 in s1
    p = strstr(s1, s2);
  
    // Prints the result
    if (p) {
        printf("String found\n");
        printf("First occurrence of string '%s' in '%s' is '%s'", s2, s1, p);
    } else
        printf("String not found\n");
  
    return 0;
}

Comments

Popular posts from this blog

Data types in C Language