C Programming 6 Jntuk
C Programming 6 Jntuk
Classes
as per the Direction of
Ministry of Education
GOVERNMENT OF
ANDHRA PRADESH
PROGRAMMING CONCEPTS FOR GATE 2021
YouTube link is to be downloaded for every class on every
day as per the given schedule
https://jntua.ac.in/gate-online-classes/registration/
Topics Covered
• Doubts clarification of pre-increment
& post-increment operators
• GATE Questions & Solutions
• Introduction to Arrays concepts
• Programs related to the concepts of
arrays
Clarification of doubts raised in Google form
1. Comma operator
#include<stdio.h> Output:
main()
{
int x, y;
}
Pre-increment & Post-increment
#include<stdio.h>
main() Output:
{
int i=5, j;
j = i++ + i++; // 1. Question
printf( “i=%d j=%d\n”, i, j);
}
Pre-increment & Post-increment
#include<stdio.h>
main() Output:
{
int i=5, j;
j = ++i + ++i; // 2. Question
printf( “i=%d j=%d\n”, i, j);
}
Pre-increment & Post-increment
#include<stdio.h>
main() Output:
{
int i=5, j;
j = ++i + i++; // 3. Question
printf( “i=%d j=%d\n”, i, j);
}
Pre-increment & Post-increment
#include<stdio.h>
main() Output:
{
int i=5, j;
j = i++ + ++i; // 4. Question
printf( “i=%d j=%d\n”, i, j);
}
Pre-increment & Post-increment
#include<stdio.h>
main() Output:
{
int i=5, j;
j = i++ + ++i + i++ + ++i + i++ + ++i ;
// 5. Question
printf( “i=%d j=%d\n”, i, j);
}
Pre-increment & Post-increment
#include<stdio.h>
main()
Output:
{
int i=5, j;
j = ++i + i++ + ++i + i++ + ++i + i++;
// 6. Question
printf( “i=%d j=%d\n”, i, j);
}
#include<stdio.h>
main()
{
int a=5;
printf("%d %d %d\n", ++a, a, a++);
} Output:
#include<stdio.h>
main()
{
int a=5;
printf("%d %d %d\n", a++, a, ++a);
} Output:
if(i=0) int
printf("true"); x=10,y=20,z=5,i;
else i=x<y<z;
printf("false"); printf("%d", i) ;
Solution 6
f(1) -- n=1
f(2) -n =2
i=2, n=n+i=2+2=4, i=3
f(4)- n=4
i=3, n=n+i=4+3=7, i=4
f(7) - n=7
2 4 4
5
Codea.c
1 int a, b, c = 0;
2 void prtFun (void);
3 int main ()
4 {
5 auto int a = 1; /* line 1 */
6 prtFun();
7 a += 1;
8 prtFun();
9 printf ( "\n %d %d " , a, b) ;
10 }
11
12 void prtFun (void)
13 {
14 register int a = 2; /* line 2 */
15 int b = 1;
16 a += ++b;
17 printf (" \n %d %d " , a, b);
18 }
1 int a, b, c = 0;
2 void prtFun (void);
3 int main ()
4 {
5 auto int a = 1; /* line 1 */
6 prtFun();
7 a += 1;
8 prtFun();
9 printf ( "\n %d %d " , a, b) ;
10 }
11
12 void prtFun (void)
13 {
14 register int a = 2; /* line 2 */
15 int b = 1;
16 a += ++b;
17 printf (" \n %d %d " , a, b);
18 }
1 3
2 4
Codeb.c
If get(6) function is being called in main( ) then how many times will the get() function be
invoked before returning to the main( )?
(a) 15
(b) 25
(c) 35
(d) 45
Arrays
• An "Array" is a group of similar data type to
store series of homogeneous pieces of data that
all are same in type.
• It is a derived data type which is created with the help
of basic data type. An array takes contiguous memory
blocks to store series of values.
• There are three types of an array: 1) One
Dimensional (One-D) Array, 2) Two Dimensional
(Two-D) Array and 3) Multi Dimensional Array.
Arrays
To process large amounts of data we need a
powerful data structure, the array. An array
is a collection of elements of the same data
type.
Since an array is a sequenced collection,
we can refer to the elements in the array as
the first element, the second element, and
so forth until we get to the last element.
29
Properties/characteristics of an array in C
language
1. An array is a derived data type, which is defined using basic data
types like int, char, float and even structures (which is called the
array of structures).
2. Array elements are stored in contiguous memory
blocks/subsequent memory blocks in primary memory.
3. Array name represents its base address. The base address is the
address of the first element of the array.
4. Array’s index starts with 0 and ends with N-1. Here, N stands for
the number of elements. For Example, there is an integer array
of 5 elements, then it’s indexing will be 0 to 4.
5. Only constants and literal values (an integer value like 5, 10,
12,...) can be assigned the number of elements in an array.
Properties/characteristics of an array in C
language
6) While declaring an array, we can also assign each element with 0
like this.
Like: int age[10]={0};
7) There is no need to provide the number of elements while
declaring an array, but we have to provide the values at the time
of declaration. In this case, array size will be the number of
values that you have provided.
Like: int age[]={21,22,25,45,56};
Here, size of the array will be 5, because there are 5 values.
8) An array can be allocated anywhere in these memory permanents:
A) Data segment for static or globally declare array
B) Heap segment for dynamically allocated array
C) Stack segment for locally declare array
/* Valid array declaration */
int main()
{
const int MAX = 100; //an integer constant
//valid arrray declaration
int students[MAX];
//valid arrray declaration
int students[100];
//more...
}
/* Invalid array declaration */
int main()
{
int MAX = 100; //an integer constant
int students[MAX];
//more...
}
34
35
Note
Only fixed-length arrays can be initialized when they are defined. Variable length
arrays must be initialized by inputting or assigning the values.
36
37
Note
One array cannot be copied to another using assignment.
38
39
Accessing Array Elements
• x and y are similar arrays (i.e., of the same data
type, dimensionality, and size), then assignment
operations, comparison operations, etc.,
involving these two arrays must be carried out
on an element-by-element basis.
• Examples using the elements of an array named
‘numbers’ are shown here:
numbers [0] = 98;
numbers [1] = numbers [0] – 11
numbers [2] = 2 * (numbers [0] – 6);
numbers [3] = 79;
numbers [4] = (numbers [2] + numbers [3] – 3)/2;
total = numbers[0] + numbers[1] + numbers[2] + numbers[3] +
numbers[4];
Cont.
• This makes statements such as:
– total = numbers[0] + numbers[1] + numbers[2] +
numbers[3] + numbers [4];
• One extremely important advantage of using integer
expressions as subscripts is that it allows sequencing
through an array using a for loop.
• Example, the for loop statements,
total = 0; /*initialize total to zero */
for(i = 0; i <5; ++i)
total = total + numbers[i]; /* add in a number */
A. Symbol table B. Activation record C. Both (a) and (b) D. Dope vector
The const feature can be applied to
A. an identifier
B. an array
C. an array argument
D. All of these
Online Test 3 at
shorturl.at/eBKS1