(1) Without using any semicolon (;) in program write a c program which output is: HELLO WORLD?
Answer:
void main()
{
if(printf("HELLO WORLD"))
{
}
}
(2)What will be output of following code?
void main()
{
char a[5];
a[0]='q';
a[1]='u';
a[2]='e';
clrscr();
printf("%s",a);
getch();
}
Output: garbage
Explanation: %s is used for string but a is not a string it is only array of character since its last character is not null character.
If you will write a[3]=’\0’; then output will be que.
(3) Write a scanf statement which can store one line of string which includes white space.
Answer:
void main()
{
char a[30];
clrscr();
scanf("%[^\n]",a);
printf("%s",a);
getch();
}
(4) Write a c program in which a scanf function can store a paragraph at time?
Answer:
void main()
{
char a[30];
clrscr();
scanf("%[^\t]",a);
printf("%s",a);
getch();
}
Note: Paragraph will end when you will press tab key.
(5)In the following program
void main()
{
extern char a[30];
}
How much array a is reserving memory space?
Answer:
It is not reserving any memory space because array a has only declared it has not initialized .Any not initialized variable doesn’t reserve any memory space.
8 comments:
meticulousy done
sir please explain how //scanf("%[^\n]",a); & scanf("%[^\t]",a); works ?
ddd
very good...
output of second question will be que
Takes in characters till new line/tab is pressed
what does the extern keyword do?
sir how to get one line statement this line scanf("%[^\n]",a); & scanf("%[^\t]",a)
Post a Comment