Important
Q1. Difference betweenn local and global variables.
BASIS FOR COMPARISON | LOCAL VARIABLE | GLOBAL VARIABLE |
---|---|---|
Declaration | Variables are declared inside a function. | Variables are declared outside any function. |
Scope | Within a function, inside which they are declared. | Throughout the program. |
Access | Accessed only by the statements, inside a function in which they are declared. | Accessed by any statement in the entire program. |
Life | Created when the function block is entered and destroyed upon exit. | Remain in existence for the entire time your program is executing. |
Storage | Local 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
Post a Comment