constants 1 (PDF)




File information


This PDF 1.4 document has been generated by Online2PDF.com / Online2PDF.com; modified using iTextSharp 5.0.5 (c) 1T3XT BVBA, and has been sent on pdf-archive.com on 23/05/2014 at 15:35, from IP address 124.123.x.x. The current document download page has been viewed 624 times.
File size: 149.48 KB (9 pages).
Privacy: public file
















File preview


C Programming Questions and Answers – Constants – 1
This se tio o o li e C test fo uses o Co sta ts . One shall practice these test questions to improve
their C programming skills needed for various interviews (campus interviews, walkin interviews,
company interviews), placements, entrance exams and other competitive exams. These questions can be
attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher,
engineering graduate or an experienced IT professional. Our online C test questions come with detailed
explanation of the answers which helps in better understanding of C concepts.

He e is a listi g of o li e C test uestio s o
solutions:

Co sta ts alo g with a swe s, e pla atio s a d/o

1. What is the output of this C code?

#include <stdio.h>

int main()

{

enum {ORANGE = 5, MANGO, BANANA = 4, PEACH};

printf("PEACH = %d\n", PEACH);

}

a) PEACH = 3
b) PEACH = 4
c) PEACH = 5

d) PEACH = 6
View Answer
Answer:c
Explanation:In enum, the value of constant is defined to the recent assignment from left.
Output:
$ cc pgm1.c
$ a.out
PEACH = 5

2. What is the output of this C code?

#include <stdio.h>

int main()

{

printf("C programming %s", "Class by\n%s Sanfoundry", "WOW");

}

a) C programming Class by
WOW Sanfoundry
b) C programming Class by\n%s Sanfoundry
c) C programming Class by
%s Sanfoundry

d) Compilation error
View Answer
Answer:c
Explanation:This program has only one %s within first double quotes, so it does not read the string
WOW .
The %s along with the Sanfoundry is not read as a format modifier while new line character prints the
new line.
Output:
$ cc pgm2.c
$ a.out
C programming Class by
%s Sanfoundry

3. For the following code snippet:
ha *st = “a fou d . o \0

t ai i g lasses ;

The character pointer str holds reference to string:
a) Sanfoundry.com
b) Sanfoundry.com\0training classes
c) Sanfoundry.comtraining classes
d) Invalid declaration
View Answer
Answer:b
E pla atio : \0 is accepted as a char in the string. Even though strlen will give length of string
“a fou d . o , i
e o st is poi ti g to e ti e st i g i ludi g t ai i g lasses

4. What is the output of this C code?

#include <stdio.h>

#define a 10

int main()

{

const int a = 5;

printf("a = %d\n", a);

}

a) a = 5
b) a = 10
c) Compilation error
d) Runtime error
View Answer
Answer:c
Explanation:The #define substitutes a with 10 leaving no identifier and hence compilation error.
Output:
$ cc pgm3.c
pg 3. : I fu tio

ai :

pg 3. :5: e o : e pe ted ide tifie o ( efo e u e i

o sta t

5. What is the output of this C code?

#include <stdio.h>

int main()

{

int var = 010;

printf("%d", var);

}

a) 2
b) 8
c) 9
d) 10
View Answer
Answer:b
Explanation:010 is octal representation of 8.
Output:
$ cc pgm4.c
$ a.out
8

6. What is the output of this C code?

#include <stdio.h>

enum birds {SPARROW, PEACOCK, PARROT};

enum animals {TIGER = 8, LION, RABBIT, ZEBRA};

int main()

{

enum birds m = TIGER;

int k;

k = m;

printf("%d\n", k);

return 0;

}

a) 0
b) Compile time error

c) 1
d) 8
View Answer
Answer:d
Explanation:m is an integer constant, hence compatible.
Output:
$ cc pgm5.c
$ a.out
8

7. What is the output of this C code?

#include <stdio.h>

#define MAX 2

enum bird {SPARROW = MAX + 1, PARROT = SPARROW + MAX};

int main()

{

enum bird b = PARROT;

printf("%d\n", b);

return 0;

}

a) Compilation error
b) 5
c) Undefined value
d) 2
View Answer
Answer:b
Explanation:MAX value is 2 and hence PARROT will have value 3 + 2.
Output:
$ cc pgm6.c
$ a.out
5

8. What is the output of this C code?

#include <stdio.h>

#include <string.h>

int main()

{

char *str = "x";

char c = 'x';

char ary[1];

ary[0] = c;

printf("%d %d", strlen(str), strlen(ary));

return 0;

}

a) 1 1
b) 2 1
c) 2 2
d) 1 (undefined value)
View Answer
Answer:d
Explanation:str is null terminated but ary is not.
Output:
$ cc pgm7.c
$ a.out
15






Download constants -1



constants -1.pdf (PDF, 149.48 KB)


Download PDF







Share this file on social networks



     





Link to this page



Permanent link

Use the permanent link to the download page to share your document on Facebook, Twitter, LinkedIn, or directly with a contact by e-Mail, Messenger, Whatsapp, Line..




Short link

Use the short link to share your document on Twitter or by text message (SMS)




HTML Code

Copy the following HTML code to share your document on a Website or Blog




QR Code to this page


QR Code link to PDF file constants -1.pdf






This file has been shared publicly by a user of PDF Archive.
Document ID: 0000164783.
Report illicit content