Test Your C Skills - Alpha
Test Your C Skills - Alpha
Test Your C Skills - Alpha
B.Bhuvaneswaran
Assistant Professor (SS)
Department of Computer Science & Engineering
Rajalakshmi Engineering College
Thandalam
Chennai 602 105
bhuvaneswaran@rajalakshmi.edu.in
E-01
Q-01
#include <stdio.h>
int x = 40;
int main()
{
int x = 20;
printf("%d", x);
return 0;
}
B.Bhuvaneswaran / AP (SS) / CSE / REC
A-01
20
E-02
In case of a conflict between two local
variables that one that is more local gets
the priority.
More local means the one nearer to the
point of usage.
Q-02
#include <stdio.h>
int main()
{
int x = 40;
{
int x = 20;
printf("%d ", x);
}
printf("%d", x);
return 0;
}
B.Bhuvaneswaran / AP (SS) / CSE / REC
A-02
20 40
E-03
Q-03
#include <stdio.h>
int main()
{
struct emp
{
char name[20];
int age;
float sal;
};
struct emp e = {"Tiger"};
printf("%d %f", e.age, e.sal);
return 0;
}
B.Bhuvaneswaran / AP (SS) / CSE / REC
A-03
0 0.000000
E-04
Q-04
#include <stdio.h>
int main()
{
int a[5] = {2, 3};
printf("%d %d %d", a[2], a[3], a[4]);
return 0;
}
B.Bhuvaneswaran / AP (SS) / CSE / REC
A-04
000
E-05
Q-06
#include <stdio.h>
int main()
{
enum status {pass, fail, atkt};
enum status stud1, stud2, stud3;
stud1 = pass;
stud2 = atkt;
stud3 = fail;
printf("%d %d %d", stud1, stud2, stud3);
return 0;
}
B.Bhuvaneswaran / AP (SS) / CSE / REC
A-05
021
E-06
E-07
E-08
E-09
E-10
E-11
E-12
E-13
E-14
The values stored in variables depends
upon where they are defined. If they are
defined outside all functions, they would
be treated as external storage class
variables and hence would contain default
values 0 and 0.0 respectively.
However, if they are defined inside a
function then they would be treated as
automatic storage class variables. In this
case the variables would contain garbage
values.
E-01
E-02
E-03
E-04
E-05
E-06
E-07
Q-07
#include <stdio.h>
int main()
{
float a = 0.7;
if(0.7 > a)
printf("Hi");
else
printf("Hello");
return 0;
}
B.Bhuvaneswaran / AP (SS) / CSE / REC
A-07
Hi
E-08
E-09
E-10
E-11
Q-11
#include <stdio.h>
int main()
{
int x = 3;
float y = 3.0;
if(x == y)
printf("x and y are equal");
else
printf("x and y are not equal");
return 0;
}
B.Bhuvaneswaran / AP (SS) / CSE / REC
A-11
03. Expressions
E-01
Arithmetic
Relational
Logical
Assignment
E-02
Expression on the right hand side of &&
and || operators does not get evaluated if
the left hand side determines the
outcome.
For example:
E-03
Q-03
#include <stdio.h>
int main()
{
int i = 2;
printf("%d %d", ++i, ++i);
return 0;
}
B.Bhuvaneswaran / AP (SS) / CSE / REC
A-03
E-04
Q-04
#include <stdio.h>
int main()
{
int i = 2;
int j = i + (1, 2, 3, 4, 5);
printf("%d", j);
return 0;
}
B.Bhuvaneswaran / AP (SS) / CSE / REC
A-04
E-05
E-06
E-07
E-01
E-02
05. Functions
E-01
E-02
E-03
E-04
E-05
E-06
E-07
E-07
E-08
E-09
E-10
E-11
E-12
E-13
E-14
E-01
E-02
E-03
E-04
E-05
E-06
E-07
E-08
E-09
#define SQR(x) (x * x)
As
E-10
E-11
07. Pointers
E-01
*ptr++ increments the pointer and not
the value pointed by it, whereas ++*ptr
increments the value being pointed to by
ptr.
++*ptr works like *ptr = *ptr + 1.
E-02
(*ptr)++
E-03
*(*(*(*(a + i) + j) + k) + l)
E-04
Q-04
#include <stdio.h>
int main()
{
char str[5] = "fast enough";
return 0;
}
A-05
No error.
E-06
E-07
E-08
stdio.h
Stddef.h
E-09
E-10
A null pointer is a pointer, which doesnt
point anywhere.
A NULL macro is used to represent the null
pointer in source code. It has a value 0
associated with it.
The ASCII NULL character has all its bits
as 0 but doesnt have any relationship
with the null pointer.
The null string is just another name for an
empty string .
08. Arrays
E-01
E-02
E-03
E-04
E-05
int arr[3][4][5];
E-06
E-07
E-08
09. Strings
11. Input/Output
References