Wednesday, 10 December 2014

Programming Quiz-6

Q: What is the output of this C code?

#include <stdio.h>

#include<string.h>
int main()

{

    char *str = "hello, world";

    char *str1 = "hello, world";

    if (strcmp(str, str1))

        printf("equal");

    else

        printf("unequal");

}

Options:

a) equal
b) unequal
c) Compilation error
d) Depends on the compiler

Answer: B

Programming Quiz-5

Q: What is the output of this C code?

#include <stdio.h>

void main()

{

    static int x;

    if (x++ < 2)

    main();

}

 Options:

a) Infinite calls to main
b) Run time error
c) Varies
d) main is called twice

Answer: D

Programming Quiz-4

Q: What is the output of this C code?

#include <stdio.h>

struct student

{

    char a[5];

};

void main()

{

    struct student s[] = {"hi", "hey"};

    printf("%c", s[0].a[1]);

}

 Options:

a) h
b) i
c) e
d) y

Answer: B

Programming Quiz-3

Q: What is the output of the below c code?

#include <stdio.h>

void main()

{

    char *s = "hello";

    char *p = s;

    printf("%p\t%p", p, s);

}

Options:

a) Different address is printed
b) Same address is printed
c) Run time error
d) Nothing

Answer: B

Programming Quiz-2

Q: What is the output of this C code?

#include <stdio.h>

void main()

{

    int x = 97;

    int y = sizeof(x++);

    printf("x is %d", x);

}

Options:

a) x is 97
b) x is 98
c) x is 99
d) Run time error

Answer:  A

Programming Quiz-1

Q: Write a program in which print 0 if 1 is provided as input and print 1 if 0 is provided.
Condition apply :
(i.) you can't use predefined function(like logical not).
(ii.) You can't use if-else condition.

Please Do comments...

Thursday, 4 December 2014

List of valid escape sequence

To learn escape sequence you can use following sentence for easy learning

Very Big Farms Need A Red Tractor

So valid escape sequence are:

\v for Vertical Tab
\b for Backspace
\f for Form Feed
\n for Newline(Line Feed)
\a for Alarm(Beep, Bell)
\r for Carriage Return
\t for Horizontal Return


Other escape sequence are:

\\ for Backslash
\' for Single Quotation Mark
\" for Double Quotation Mark
\? for Question Mark

Wednesday, 3 December 2014

How to read string of any size in C++?

#include<iostream.h>
#include<stdio.h>
#define SIZE 1
void main( )
{
             char* str[SIZE];
             gets(str[0]);         //Read string of any string
             cout<<str[0];      
 }