0% found this document useful (0 votes)
4 views

c language output finding

The document contains a series of C programming code snippets, each followed by a request to determine their output. The snippets cover various programming concepts including conditional statements, string manipulation, and memory handling. The outputs of these programs vary based on the logic implemented in each code segment.

Uploaded by

dgpguru
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

c language output finding

The document contains a series of C programming code snippets, each followed by a request to determine their output. The snippets cover various programming concepts including conditional statements, string manipulation, and memory handling. The outputs of these programs vary based on the logic implemented in each code segment.

Uploaded by

dgpguru
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

SET-1: Find the output of the following programs,

1)#include <stdio.h>
int main()
{
int x = 400, y, z;
if (x >= 500)
y = 400;
z = 300;
printf("%d %d\n", y, z);

return 0;
}

2) #include <stdio.h>
int main()
{
int p = 800, q, r;

if (p >= 700)
q = 600;
r = 500;
printf("%d %d\n", q, r);
return 0;
}
3)#include <stdio.h>
int main()
{
int a = 30, b = 40;

if (a == b);

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

return 0;
}
4)#include <stdio.h>

int main()
{
int e = 4;
float f = 4.0;
if (e == f) {
printf("E and F are equal\n");
}
else {
printf("E and F are not equal");
}
return 0;
}
5)#include <stdio.h>
int main()
{
int p = 4, q, r;

q = p = 15;
r = p < 15;
printf("p = %d q = %d r = %d\n", p, q, r);

return 0;
}
6)#include <stdio.h>

int main()
{
int i = 65;

char j = 'A';

if (i == j) {

printf("This place is beautiful\n");


}

else {
printf("This place is not beautiful\n");
}

return 0;
}
7)#include <stdio.h>

int main()
{
float p = 13.25, q = 14.5;

if (p = q) {
printf("Hello\n");
}

return 0;
}

SET-2 :Find the output of the following programs,

8)#include <stdio.h>
int main()
{
int k = 14, l = 12;
if (l >= k)
{
l = k;
k = l;
printf("%d, %d\n", k, l);
}
return 0;
}
9)#include <stdio.h>
int main()
{
if ('Y' < 'y') {
printf("ASCII value of Y is smaller than that of y\n");
}
else {
printf("ASCII value of y is smaller than that of Y\n");
}
return 0;
}

10) #include <stdio.h>


int main()
{
int j = 16, k = 25;
if (j % 2 == k % 5) {
printf("Solve\n");
}
return 0;
}
11) #include <stdio.h>
int main()
{
int a = 50, b = 100;
if (a == b / 2) {
printf("Hello");
}
else {
printf("Hi");
}
return 0;
}
12) What will be the output of the below program, if input values are 1 and 2?

#include <stdio.h>
int main()
{
int r, s, c;
c = scanf("%d%d", &r, &s);
if (r + s - c) {
printf("This is a game");
}
else {
printf("you have to play it");
}
return 0;
}

13)#include <stdio.h>
int main()
{
printf("%s\n",4+"Hello world");
printf("%s\n","Hello world"+4);
return 0;
}
2)#include <stdio.h>
#include <string.h>

int main()
{
char str[]="Hello";

str[strlen(str)+1]='#';
printf("str= %s\n",str);

return 0;
}
14)#include <stdio.h>

int main()
{
char str[]={0x41,0x42,0x43,0x20,0x44,0x00};
printf("str= %s\n",str);
return 0;
}
15)#include <stdio.h>
int main()
{
char str[]="Hello";
char *ptr=str;

while(*ptr!='\0')
printf("%c",++*ptr++);

printf("\n");

return 0;
}
16)#include <stdio.h>
int main()
{
char str[5]={0},loop=0;

while(loop<5)
printf("%02X ",str[loop++]);
printf("\n");

return 0;
}
17) In C, what will be the output of the given code?
#include <stdio.h>
#include <string.h>
int main()
{
char *s1, *s2;
s1= "abcdef" ;
s2= "abcdeg" ;
printf(" %d ", strcmp (s1,s2));
printf(", ");
s1="abcdef";
s2="abcdef";
printf(" %d ", strcmp (s1,s2));
printf(", ");
s1="abcdef";
s2="abcdee";
printf(" %d ", strcmp (s1,s2));
printf(", ");
return 0;
}
18) Which function is used to find the last occurrence of character in C?
#include <stdio.h>
#include <string.h>
int main()
{
char document[] = "I love IncludeHelp.com This is an amazing website ";
char *s, *p ;
char character2 = 'x', character1 = 't';

s = strrchr(document, character1 );
p = strrchr(document, character2 );

if (s)
printf("The position of '%c' is %d\n", character1, s-document);
else
printf("The character was not found in given document\n");

if (p)
printf("The position of '%c' is %d\n", character2 , p-document);
else
printf("The character was not found in given document\n");

return 0;
}
19) In C, what will be the output of following program?

#include <stdio.h>
#include <string.h>

int main()
{
char a[] = "%d\n";
a[5] = 'i';

printf(a, 85);
return 0;
}

20) In C, what will be the output of following program?

#include <stdio.h>
#include <string.h>

int main()
{
char a[] = "Include Help";
char *b = "Include Help";

printf("%d, %d, ", sizeof(a), sizeof(b));


printf("%d, %d", sizeof(*a), sizeof(*b));

return 0;
}

You might also like