Find output of C programs Questions with Answers (Set - 2)

Question - 1

#include <stdio.h>
int main()
{
	int x;
	x = 10;
	
	if(x > 10)
		x -= 10;
	else if(x >= 0)
		x += 00;
	else if(x)
		x += 10;
	else
		x -= 10;
	
	printf("%d\n",x);
	return 0;
}

Output

10

Question - 2

#include <stdio.h>
int main()
{
	int a = -10, b = 20;
	
	if(a > 0 && b < 0)
		a++;
	else if(a < 0 && b < 0)
		a--;
	else if(a < 0 && b > 0)
		b--;
	else
		b--;
	
	printf("%d\n",a + b);
	return 0;
}

Output

9

Question - 3

#include <stdio.h>
int main() 
{
	int a= -1,b = -a;
	int x,y;
	
	x = (a> 0) && (b < 0) || (a< 0) && (b > 0);
	y = (a<= 0) || (b >= 0) && (a>= 0) || (b <= 0);
	
	printf("%d\n",x == y);
	
	return 0;
}

Output

1

Question - 4

#include <stdio.h>
int main()
{
	int a=10,b=20,*p,s=0;
	
	p = &a;
	a++;
	(*p)++;
	s = a + b + *p;
	
	printf("%d\n",s);
	return 0;
}

Output

44

Question - 5

#include <stdio.h>
#include <string.h>
int main() 
{
	char str[20] = "ABCDEFGHIJK";
	int s = strlen(str);
	
	str[3] = '\0';
	s = strlen(str);
	
	printf("%d\n",s);
	return 0;
}

Output

3

Question - 6

#include <stdio.h>
#include <string.h>
int main()
{
	char str[20] = "ABCDEFGHIJK";
	int s = strlen(str);
	
	str[3] = '\0';
	s += strlen(str);
	strcpy(str,"ABCDEF");
	s += strlen(str);
	strcat(str,"ABC");
	s += strlen(str);
	
	printf("%d\n",s);
	return 0;
}

Output

29





Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.