C Language Practice Programs 1
Determine output:
#include <stdio.h>
void main()
{
char *p = NULL;
char *q = 0;
if(p)
printf(” p “);
else
printf(“nullp”);
if(q)
printf(“q”);
else
printf(” nullq”);
}
- p q
- Depends on the compiler
- x nullq where x can be p or nullp depending on the value of NULL
- nullp nullq
Ans: 4
What is the output?
#include <stdio.h>
void main()
{
printf(“Hi Friends”+3);
}
Output: Friends
The address operator &, cannot act on
- Constants
- Arithmetic expressions
- Both of the above
- Local variables
Ans: 3
What is the output?
#include <stdio.h>
void main()
{
int a[][3]={0,1,2,3,4,5};
printf(“%d”,sizeof(a));
}
Ans: 12 or 24
#include<stdio.h>
void main()
{
int *ptr, a=10;
ptr = &a;
*ptr += 1;
printf(“%d, %d”, *ptr, a);
}
- 10, 10
- 10, 11
- 11, 10
- 11, 11
Ans: 4
Attend Free Demo and Learn C LANGUAGE ONLINE TRAINING by Real-Time Expert
What is the output?
#include <stdio.h>
void main()
{
void x(void);
x();
return 0;
}
void x(void)
{
char a[]=”HELLO”;
char *b = “HELLO”;
char c[10]=”HeLLO”;
printf(“%s %s %s\n”,a,b,c);
printf(“%d %d %d\n”,sizeof(a),sizeof(b),sizeof(c));
}
Output: 6 4 10
Determine Output:
void main()
{
char *str1 = “abcd”;
char str2[] = “abcd”;
printf(“%d %d %d”, sizeof(str1), sizeof(str2), sizeof(“abcd”));
}
- 2 5 5
- 2 4 4
- 8 5 5
- 2 4 5
Ans: 3
what is the output?
#include <stdio.h>
void main()
{
register int x =5, *p;
p = &x;
printf(“%d”,*p);
}
Ans: Error
What will be printed after compiling and running the following code?
main()
{
char *p;
printf(“%d %d”,sizeof(*p), sizeof(p));
}
- 1 1
- 1 2
- 2 1
- 2 2
Ans: 2