C Programming
C Programming
C Programming
C Programming
Important Topics for C programming M.C.Q: Data type, variable, iteration, size of data
type, logic, control statement, break,continue, output, string output and previous questions.
Ans.: 8 4 2 4
Solution:
Hereprintf ("%d\t", sizeof (6.5));is a double value. So, size of double value is 8
bytes. Next line print sizeof integer which size is 4 byte and the third line character constant is 2
bytes (size of char data type is one byte). The fourth line is treated as integer which size is 4
bytes.
char
%c Character
unsigned char
short
unsigned short
%d Signed Integer
int
long
float
%e or %E Scientific notation of float values
double
%f Floating point float
%lf Floating point double
A Short Guide to Preliminary Exam 3 C Programming
%p Address of pointer to void void * void *
unsigned int
%u Unsigned Integer
unsigned long
7. Which one is the not basic data type of c programming?[SBL (AP)-2016]
a) Char b) int c) void d) None of this
Ans.: c
8. Suppose a C program has floating constant 1.414, what's the best way to convert it as
afloat data type?[Combined (Officer- IT/ICT)-2019]
a) (float)1.414 b) float(1.414) c) 1.414f or 1.414F d) None of these Ans. c
Explanation: By default, floating constant is of double data type. By suffixing it with f or
F,can be converted to float data type.
9.What is the output of the following program?[SBL (AP)-2016]
int main ()
{
printf("%.3f", 8/((3*8)*3));
return 0;
}
a) 0.000 b) 1.000 c) 0.111 d) None
Ans.: a
Explanation:
The call of printf has undefined behavior because the conversion specifier %f does not
correspond to the type of the expression of int.
10.Consider the following variable declarations and definitions in C. [Combined (Ofc- IT/ICT)-2019]
i. int var_9=1
ii. int 9_var=2
iii. int _=3
Choose the correct statement above variables.
a) Both i) and ii) are valid b) Only i) is valid
c. Both i) and iii) are valid d) All of these
Ans.: c
Explanation:
Every variable name should start with alphabets or underscore (_).
No spaces are allowed in variable declaration.
Except underscore (_) no other special symbol are allowed in the middle of the variable
declaration (not allowed -> roll-no, allowed ->roll_no).
Maximum length of variable is 8 characters depend on compiler and operation system.
Every variable name always should exist in the left-hand side of assignment operator
(invalid -> 10=a; valid -> a=10;).
No keyword should access variable name (int for invalid because for is a keyword).
Note: scanf(“%s”,str); does not read string type which contain white space. Hence to read multi
word string use gets(str).
16. Which of following comment regarding the reading of a string using scanf() and gets () is
true?
a) scanf is delimited by blank, gets is delimited by end of line
b) scanf is delimited by end of line, gets is delimited byblank space
c) Both can be used interchangeably
d) None of these
Ans.: a
17.int C=10; printf(“%d”,c--); given output off----[Combined(AP)-2019]
a) 10 b)11 c) 9 d)8
Ans.: a
A Short Guide to Preliminary Exam 5 C Programming
Explanation:
Operator Operator/Description
Pre increment operator (++i) value of i is incremented before assigning it to the variable i
Post increment operator (i++) value of i is incremented after assigning it to the variable i
Pre decrement operator (-- i) value of i is decremented before assigning it to the variable i
Post decrement operator (i--) value of i is decremented after assigning it to variable i
18. Which of the following will not increase the value of variable c by 1?[BREB(IT)-2016]
a) C++ b) C = C+1 c) C+1 >= C d) C+= 1
Ans.: c
19. What is the output of following program?
int main ()
{
int c=10;
printf("%d\t",c); // print 10
printf("%d\t",c++);// increment but not execute this line so
print 10
printf("%d\t",++c);// ++ imediate increment also execute
previous step so print 12
printf("%d\t",c--);// decrement but execute in next line so
print 12
printf("%d\t",--c);// imediate decrement with previous line so
print 10
return 0;
}
Ans.: 10 10 12 12 10
20. What is the output of the following program?[JBL(SO-IT/ICT)-2016]
int main ()
{
int i = 0;
int x = i++, y = ++i;
printf ("%d %d", x, y);
return 0;
}
a) 0,2 b) 0,1 c) 1,2 d) undefined
Ans.: a
Output: x=300
int main()
{
A Short Guide to Preliminary Exam 9 C Programming
char *str = "abcde";
printf ("%c", *str);
printf ("%c", *str++);
printf ("%c", *(str++));
printf ("%s", str);
return 0;
}
Ans.: aabcde
40. What is the output of the following program?
int main()
{
char str[]="Heal";
printf("%c",str[4]);
return 0;
}
a) H b) l c) d d) None
Ans.: d
41. Which function will you choose to join two words?
a) strcpy() b) strcat() c) strncon() d) memcon()
Ans.: b
Explanation: The strcat() function is used for concatenating two strings, appends a copy of the
string.
char *strcat(char *s1,const char *s2);
List of String function:
strcat- concatenate two strings
strchr- string scanning operation
strcmp - compare two strings
strcpy - copy a string
strlen- get string length
strncat - concatenate one string with part of another
strncmp - compare parts of two strings
strncpy - copy part of a string
strrchr - string scanning operation
42. Which of the following function returns a pointer to the located string or a null pointer
if string is not found.
a) strtok() b) strstr() c) strspn() d) strrchr()
Ans.: b
Explanation: The strstr() function is used to return a pointer to the located string, or if string is not
found a null pointer is returned.
43. The______ function returns the number of characters that are present before the
terminating null character.
a) strlength() b) strlen() c) strlent() d) strchr()
Ans.:b
A Short Guide to Preliminary Exam 10 C Programming
Explanation: The strlen() function is used to return the number of characters that are present
before the terminating null character.size-t strlen(const char *s);The length of the string pointed
to by s is computed by strlen().
44.To store address in c programming which one is used? [ANE -BPSC -2019]
a) Break b) pointer c) char d) float
Ans.: b
int main()
{
char *a[2] = { "hello", "hi" };
printf ("%s", *(a + 1));
return 0;
}
Output: hi
Function Purpose
Allocates the memory of requested size and returns the
malloc
pointer to the first byte of allocated space.
Allocates the space for elements of an array. Initializes the
calloc
elements to zero and returns a pointer to the memory.
It is used to modify the size of previously allocated memory
realloc
space.
Free Frees or empties the previously allocated memory space.
1. Suppose a C program has floating constant 1.414, what's the best way to convert it as a
float data type? [Combined(O-IT/ICT)-2019]
a) (float)1.414 b) float(1.414) c) 1.414f or 1.414F d) None of these Ans.: c
2. Which of the declaration is correct?[Combined(O-IT/ICT)-2019]
a) int length; b) char int c)int long; d) float double; Ans.: a
3.An n*n armay v is defined as follows: v[i, j]=i-j for all i,j; 1<=i<=n, 1<=j<=n , the sum
of the element of array v is [Combined(O-IT/ICT)-2019]
a) 0 b) n-1 c) n -3n+2
2
d) n (n+1)/2
2
Ans.: a
4. An array contains the following letters, Color = {E, L,E,C,T,I,O,N) The value of the
variable, E=3. Color [E] points to which value? [Combined(SO-IT/ICT)-2018]
a) E b) C c) T d) 1 Ans.: b
5. int C=10; System.out.println(C--); gives a output of ---- [Combined(SO-IT/ICT)-2018]
a)10 b) 11 c) 9 d) 8 Ans.: a
6.What is an example of iteration in C? [Combined(AP)-2018]
a) for b) while c) do-while d) all of the above Ans.: d
7.Which of the following doesn’t require an & for the input in scanf()? [Combined(AP)-2018]
a) char name[10]; b) int name[10]; c) float name[10]; d) double name[10]; Ans.: a
8. int number[]={10,20,30,40,50}; number[3]=? [SBL,JBL (SO-IT/ICT)-2018]
a) 10 b) 20 c) 30 d) 40 Ans.: d
9.What is the final values of a and c in the following C statement?
(initialize value a=2,c=1) c=c? a=0:2;[Combined(AP)2018]
a) a=0,c=0 b) a=2,c=2 c) a=2,c=2 d) a=1,c=2 Ans.: a
10.What is the length of character pointer in below code? [ICB(AP)2017]
char *str="Hello"; printf("%d",strlen(str));
A Short Guide to Preliminary Exam 14 C Programming
a) 3b)5 c)2 d)undefined Ans.: b
11.Which control statement can be executed at least once?[ICB(AP)2017]
a) While b)for c) do—while d) All of the above Ans.: c
12. Which of the following cannot be checked in a switch-case statement?[ICB(AP)2017]
a) Character b)Integer c) Float d) None of the above Ans.: c
13. Which of the following will not increase the value of variable c by 1?[BREB 2016]
a) C++ b) C = C+1 c) C+1 >= C d) C+= 1 Ans.: c
14. Which is logical operator?
a) +b)>= c) AND d)<< Ans.: c
15. Which Format Specifier is used for typing double datatype?
a)%f b)%1f c)%d d)%s Ans.: b
Summary
'C' was developed by Dennis Ritchie in 1972.
It is a low programming level language close to machine language
It is widely used in the software development field.
It is a procedure and structure-oriented language.
It has the full support of various operating systems and hardware platforms.
Many compilers are available for executing programs written in 'C'.
A compiler compiles the source file and generates an object file.
A linker links all the object files together and creates one executable file.
The main function is a mandatory part of every 'C' program.
To use the functionality of a header file, we have to include the file at the beginning of
our program.
There are total 32 keywords.
A constant is a value that doesn't change throughout the execution of a program.
There are four commonly used data types such as int, float, char and a void.
We can also nest if-else within one another when multiple paths have to be tested.
Looping is one of the key concepts on any programming language.
It executes a block of statements number of times until the condition becomes false.
Loops are of 2 types: entry-controlled and exit-controlled.
'C' programming provides us 1) while 2) do-while and 3) for loop.
A switch is used in a program where multiple decisions are involved.
A switch must contain an executable test-expression.
Each case must include a break keyword.
A string is a sequence of characters stored in a character array.
A character such as 'd' is not a string and it is indicated by single quotation marks.
'C' provides standard library functions to manipulate strings in a program. String
manipulators are stored in <string.h> header file.
Auto, extern, register, static are the four storage classes in 'C'.