0% found this document useful (0 votes)
39 views71 pages

Gate Pyqs DS

The document outlines a GATE online coaching program directed by the Ministry of Education in Andhra Pradesh, covering programming concepts for GATE 2021. It includes topics such as GATE questions from previous papers, string functions, and structures, along with references for further reading. Additionally, it provides examples of C functions and string library functions, detailing their roles, inputs, outputs, and usage.

Uploaded by

hasiniganeda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views71 pages

Gate Pyqs DS

The document outlines a GATE online coaching program directed by the Ministry of Education in Andhra Pradesh, covering programming concepts for GATE 2021. It includes topics such as GATE questions from previous papers, string functions, and structures, along with references for further reading. Additionally, it provides examples of C functions and string library functions, detailing their roles, inputs, outputs, and usage.

Uploaded by

hasiniganeda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 71

GATE Online Coaching

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 – DAY 9
• GATE questions from previous papers

• String functions

• Introduction to Structures
References
1. Mittal, Ajay. Programming in C: A Practical Approach. Pearson Education India, 2010.
2. Ritchie, Dennis M., Brian W. Kernighan, and Michael E. Lesk. The C programming language. Englewood Cliffs:
Prentice Hall, 1988.
3. Venugopal, K. R., and Sudeep R. Prasad. Mastering C. McGraw-Hill Education, 2007.
4. Venkateswarlu, B., and E. V. Prasad. "Data Structures." S. Chand Publications (2002).
Consider the following C function.
void convert(int n){
if(n<0)
printf(“%d”, n);
else {
convert(n/2);
printf(“%d”,n%2);
}
}
Which one of the following will happen when the function convert is called with any positive
integer n as argument?
(A) It will print the binary representation of n and terminate
(B) It will print the binary representation of n in the reverse order and terminate
(C) It will print the binary representation of n but will not terminate
(D) It will not print anything and will not terminate
Which one of the following values will
be displayed on execution of the
programs?
(A) 41
(B) 52
(C) 63
(D) 630
The number of times the variable
sum will be printed, when the above
program is executed, is ??.
GATE-2018 Explanation: fun1(char *s1, char *s2)
Question-5-Answer Above function scope is local, so the value changed
here won’t affect actual parameters. SO the values
will be ‘Hi Bye’.

fun2(char **s1, char **s2)


In this function value is pointer to pointer, so it
changes pointer of the actual value. So values will
be ‘Bye Hi’

Answer: (A) --- Hi Bye Bye Hi


One Dimensional Array
Two Dimensional Array
GATE 2020
1. Consider the following C program.
2. #include<stdio.h>
3. int main()
4. {
5. int a[4][5] = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10},
{11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}};
6. printf("%d\n", *(*(a+**a+2)+3));
7. return (0);
8. }
*(*(a+**a+2)+3)
POINTERS -2016

GATE-2016
Question-1
GATE-2016
Question-1: Answer
GATE-2015
Question-2
GATE-2015
Question-2-Answer
GATE-2019
Question-3
GATE-2019
Question-3: Answer
GATE-2016
Question-6
GATE-2016
Question-7
GATE-2016
Question-7-Answer
Explanation: Note that a and d are not
swapped as the function mystery() doesn’t
change values, but pointers which are local
to the function.
Answer: 2016
String Library Functions
The C string library provides a large number of
functions that can be used for string
manipulations.
S. No. Function name Prototype Role

1. strlen int strlen(const char* s) Calculates the length of a strings.

2. strcpy char* strcpy(char* dest, const char* src); Copies the source string str to the
destination string dest.
3. strcat char* strcat(char *dest, const char*src); Appends a copy of the stringsrc to
the end of the stringdest.

4. strcmp int strcmp(const char*s1, const char* Compares two strings.


s2);
5. strcmpi int strcmpi(const char*s1, const char* Compares two strings without case
s2); sensitivity.
6. strrev char* strrev(char* s); Reverses the content of a string s.

7. strlwr char* strlwr(char* s); Converts the string to lowercase.

8. strupr char* strupr(char* s); Converts the string to uppercase.


9. strset char* strset(char* s, int ch); Set all characters in a string s to the characterch.

10. strchr char*strchr(const char* s, int c); Scans a string for the first occurrence of a given
character.
11. strrchr char*strrchr(const char*s, int c); Finds the last occurrence of a char c in the string s.

12. strstr char* strstr(const char* s1, Finds the first occurrence of a substring (i.e. s2) in
const char* s2); another string (i.e. s1).

13. strncpy char* strncpy(char* dest, const Copies at the most n characters of the string src to the
char* src, int n); string dest.

14. strncat char* strncat(char* dest, const Appends at the most n characters of the string src to
char* src, int n); the string dest.

15. strncmp int strcmp(const char* s1, const Compares at the most n characters of two stringss1
char* s2, int n); and s2.
16. strncmpi int strcmp(const char* s1, const Compares at the most n characters of two stringss1
char* s2, int n); and s2 without case sensitivity.

17. strnset char* strnset(char* s, int ch, int Sets the first n characters of the string s to the
n); character ch.
1. strlen function

 Role:
The strlen function is used to find the length of a string.
 Input:
The input to strlen function can be a string literal constant or a
character array holding the string or a character pointer
pointing to a string.
 Output:
The strlen function returns the length of a string literal. The
terminating null character is not counted while determining the
length of a string.
USAGE
//Library Function //User defined Function Output window:
#include<stdio.h> #include<stdio.h>
#include<string.h> int mystrlen(char* s); length of strings::
main() main() Hello is 5
{ { Dear is 4
char *ptr=”Dear”; char *ptr=”Dear”; Reader is 6
Remarks:
char name[50]=”Reader”; char name[50]=”Reader”; 1.) The strlen function
printf(“length of strings::\n”); printf(“length of strings::\n”); returns the number of
printf(“Hello is %d\n”, printf(“Hello is %d\n”, characters that precede
strlen(“Hello”)); mystrlen(“Hello”)); the terminating null
printf(“Dear is %d\n”, strlen(ptr)); printf(“Dear is %d\n”, character.
printf(“Reader is %d\n”, mystrlen(ptr)); 2.) If terminating null
strlen(name)); printf(“Reader is %d\n”, character is not present at
} mystrlen(name)); the end of a string, the
} strlen function gives the
int mystrlen(char *s) arbitrary result.
{int i=0;
while(*(s+i)!=’\0’) i++;
return i;}
2. strcpy function
 Role:
The strcpy function copies the source string to the
destination string.
 Inputs:
A source string and a destination string. The source string can be
a string literal or a character array or a character pointer pointing
to a string. The destination should be a character array or a
character pointer to the memory location in which the source
string is to be copied.
 Output:
The strcpy function copies the source string to the destination and
returns a pointer to the destination string.
USAGE
//Library function //User defined function
#include<stdio.h> #include<stdio.h>
#include<string.h> char* mystrcpy (char* dest, const char* src);
main() main()
{ {
char src[50]=”Hello”; char src[50]=”Hello”; char dest[50];
char dest[50]; puts(“Source string is”); puts(src);
puts(“Source string is”); mystrcpy (dest, src);
puts(src); puts(“Destination string is”); puts(dest);
strcpy (dest, src); }
puts(“Destination string is”); char* mystrcpy(char* dest, const char* src)
puts(dest); {
} int i=0;
while(src[i]!=’\0’)
{dest[i]=src[i];
i++;}
//Null character should be explicitly placed at the end of //the
string.
dest[i]=’\0’;
return dest;
}
Output Window:
Source string is
Hello
Destination string is
Hello

Remarks:
• The destination string should not be a string literal
constant. Although, if a string literal constant is provided,
there will be no compilation error.

• If the number of characters in the source string is more


than the number of characters that the destination can
hold, a memory exception may arise.
3.strcat function
 Role:
The strcat function concatenates one string with another. It
appends a source string to the destination string.
 Inputs:
The source string to be appended and the destination string to
which the source string is to be appended. The first argument of
function strcat can be a character array or a character pointer but
should not be a string literal constant.
 Output:
The strcat function appends a source string to the destination
string and returns a pointer to the destination string.

USAGE
//Library Function //User defined function Output Window:
#include<stdio.h> #include<stdio.h>
The strings are::
#include<string.h> char* mystrcat(char* dest, const char* src);
Hello
main() main()
{ { char dest[50]=”Hello”; Readers!!
char dest[50]=”Hello”; char src[50]=”Readers!!”; After concatenation::
char src[50]=”Readers!!”; puts(“The strings are::”); HelloReaders!!
puts(“The strings are::”); puts(dest); puts(src); Remarks:
puts(dest); mystrcat(dest,src);  The length of the destination
puts(src); puts(“After concatenation::”); string after concatenation= the
strcat(dest,src); puts(dest); } length of the destination string
puts(“After concatenation::”); before concatenation + the length
puts(dest); char* mystrcat(char* dest, const char* src) of the source string.
} {  The destination should be big
int i=0, j=0; enough.
while(dest[i]!=’\0’) i++;  If not, the characters of resulting
while(src[j]!=’\0’) string would be placed in
{dest[i]=src[j]; i++; j++;} unreserved memory and hence
dest[i]=’\0’; memory exception may occur.
return dest;}
4. strcmp function
 Role:
The strcmp function compares two strings.
 Inputs:
Two strings str1 and str2 to be compared, in the form of string
literal constants or character arrays or character pointers to the
memory locations in which the strings to be compared are stored.
 Output:
The strcmp function performs the comparison of str1 and str2,
starting with the first character in each string and continuing with
the subsequent characters until the corresponding characters differ
or until the end of the strings is reached. It returns the ASCII
difference of the first dissimilar corresponding characters
or zero if none of the corresponding characters in both the
strings are different. USAGE
//Library function //User defined function

#include<stdio.h> #include<stdio.h> int mystrcmp(const char* s1, const


#include<string.h> int mystrcmp(const char* s1, const char* s2)
main() char* s2); {
{ main() int i=0;
char str1[20],str2[20]; { while(s1[i]!=’\0’ || s2[i]!=’\0’)
int res; char str1[20],str2[20]; {
puts(“Enter string 1:”); int res; if(s1[i]!=s2[i])
gets(str1); puts(“Enter string 1:”); return(s1[i]-s2[i]);
puts(“Enter string 2:”); gets(str1); i++;
gets(str2); puts(“Enter string 2:”); }
res=strcmp(str1,str2); gets(str2); return 0;
if(res==0) res=mystrcmp (str1,str2); }
puts(“Strings are equal”); if(res==0)
else puts(“Strings are equal”);
puts(“Strings are not equal”); else
} puts(“Strings are not equal”);
}
Output window (1st execution): Output window (2n execution):
Enter string 1: Enter string 1:
Hello Hello
Enter string 2: Enter string 2:
Hi Hello
Strings are not equal Strings are equal
Output window (3rd execution):
Enter string 1:
hello
Enter string 2:
HELLO
Strings are not equal
Remarks:
• strcmp(str1,str2) returns a value:
• 0 if str1 and str2 are equal, or
• >0 if str1 is greater than str2 i.e. str1 comes after str2 in lexicographic order (i.e.
dictionary order), or
• <0 if str1 is lesser than str2 i.e. str comes before str2 in lexicographic order.
5. strcmpi function

 Role:
The strcmpi function compares two strings without case sensitivity. The
suffix character ‘i' in strcmpi stands for ignore case.
 Inputs:
Two strings str1 and str2 to be compared, in the form of string literal constants
or character arrays or character pointers to the memory locations in which the
strings to be compared are stored.
 Output:
The strcmpi function performs comparison of strings str1 and str2 without case
sensitivity. It returns the ASCII difference of the first different corresponding
characters or zero if none of the corresponding characters in both the strings are
different.

USAGE
//Library function //User defined function

#include<stdio.h> #include<stdio.h> int mystrcmpi(const char* s1, const


#include<string.h> int mystrcmpi(const char* s1, const char* s2)
main() char* s2); {
{ main() int i=0;
char str1[20],str2[20]; { while(s1[i]!=’\0’ || s2[i]!=’\0’)
int res; char str1[20],str2[20]; {
puts(“Enter string 1:”); int res; if((s1[i]==s2[i])||(s1[i]-
gets(str1); puts(“Enter string 1:”); s2[i])==32||(s1[i]-s2[i])==-32)
puts(“Enter string 2:”); gets(str1); i++;
gets(str2); puts(“Enter string 2:”); else
res=strcmpi(str1,str2); gets(str2); return(s1[i]-s2[i]);
if(res==0) res=mystrcmpi(str1,str2); }
puts(“Strings are equal”); if(res==0) return 0;
else puts(“Strings are equal”); }
puts(“Strings are not equal”); else
} puts(“Strings are not equal”);
}
Output window (1st execution): Output window (2nd
execution):
Enter string 1:
Enter string 1: Hello
HELLO Enter string 2:
Enter string 2: Hi
hello Strings are not equal
Strings are equal
Output window (3rd execution):

Enter string 1:
hello
Enter string 2:
HELLO
Strings are equal
Remarks:
• The Turbo C 4.5 compiler does not provide the strcmpi function.
• Lower case letters have ASCII value 32 more than their upper case
counterparts.
• ‘a’ has ASCII value 97 while ‘A’ has ASCII value 65.
6. strrev function

 Role:
The strrev function reverses all the characters of a
string except the terminating null character.
 Inputs:
A string in the form of a character array or a character
pointer or a string literal constant. .
 Output:
The strrev function reverses the string and returns a pointer
to the reversed string.

USAGE
//Library Function //User defined function Output Window:
#include<stdio.h>
#include<stdio.h> char* mystrrev(char* s);
#include<string.h> Hello
main()
main() { After reversal, the string is:
{ char str[20]; olleH
char str[20]; puts(“Enter a string:”); Output Window (2nd ):
puts(“Enter a string:”); gets(str);
gets(str); mystrrev(str);
strrev(str); puts(“After reversal, the string is:”); Enter a string:
puts(“After reversal, the puts(str); Hello Readers
string is:”); } After reversal, the string is:
puts(str); char* mystrrev(char* s)
}
sredaeR olleH
Remarks:
{
int i=0, j=0; The Turbo C 4.5 compiler does not
char temp; support the strrev function.
while(s[i]!=’\0’) i++; The strrev function can also be
i--; applied on the string literals i.e.
while(i>j) strrev(“Hello”)=”olleH”
{temp=s[i]; s[i]=s[j]; s[j]=temp; strrev(strrev(“String”))=”String”
j++;i--;} i.e. Reversal of reverse of a string is
return s; the string itself.
}
List of strings
Can be stored in two ways
1. • Using array of strings

2. • Using array of character


pointers
1. Array of strings
• Since, a string itself is stored in one-dimensional character array,
list of strings can be stored by creating an array of one-
dimensional character arrays i.e. two-dimensional character
arrays.
• A 2-D char array

1st string
R a m a n \0

2nd string S a m \0

3rd string V i s h a l \0

4th string N e h a \0
declaration of Array of strings
• The general form of array of strings declaration is:
<sclass_specifier><type_qualifier><type_modifier>char
identifier[<row_specifier>][column_specifier]<=initialization_list>;
The following are the important points about array of strings
declaration:
1. Array of strings declaration consists of char type specifier, an
identifier name, row size specifier and column size specifier. The
following declarations are valid:
• char array1[2][30]; //array1can store 2 strings of maximum 30
• char array2[5][5]; //array2 can store 5 strings of maximum 5

2. All the syntactic rules discussed for declaring two-dimensional


arrays are applicable for declaring array of strings as well.
3. Initialization of array of strings: Array of strings can be initialized in two
ways:
Using string literal constants: Using string literal constants, array of strings
can be initialized as:

char str[][20]={
“Raman”,
“Sam”,
“Vishal”,
“Neha”
};
Using list of character initializers: Using list of character initializers, array
of strings can be initialized as:

char str[][20]={ {‘R’,’a’,’m’,’a’,n’,’\0’},


{‘S’,’a’,’m’,’\0’},
{‘V’,’i’,’s’,’h’,’a’,’l’,’\0’},
{‘N’,’e’,’h’,’a’,’\0’}
};
reading list of strings from the terminal
• A list of strings can be read from the terminal by iteratively calling gets
function.
//Reading a list of strings from the terminal if(ch==’Y’||ch==’y’)
#include<stdio.h> i=i+1;
main() else
{ break;
int i=0,j=0, marks[10], max; if(i==10)
char students[10][20], ch; {
printf(“Enter names of students and their printf(“Cannot hold more names\n”);
marks:\n”); break; }
while(1) }
{ max=0;
scanf(“%s %d”, students[i], &marks[i]); for(j=0;j<=i;j++)
printf(“Do you want to enter more(Y/N)\t”); if(marks[j]>marks[max])
flushall(); // fflush(stdin); max=j;
scanf(“%c”,&ch); printf(“\n %s got maximum marks”,
students[max]);
}
Output Window:
Enter names of students and their marks:
Praveen 89
Do you want to enter more(Y/N) Y
Ashok 80
Do you want to enter more(Y/N) Y
Manish 90
Do you want to enter more(Y/N) Y
Ameet 85
Do you want to enter more(Y/N) N

Manish got maximum marks

Remarks:
• List of strings can be read by iteratively using gets function.
• The role of flushall function is to flush (i.e. clear) the contents
of all the streams.
2.Array of character pointers
• An array of strings can also be stored by using an array
of character pointers. The starting addresses of strings are
stored in an array of character pointers as shown in the figure
below:
char* languages[]={“Basic”, “Java”, “Fortran”, “C”, “C++”};
languages B a s i c \0
2000 2001 2002 2003 2004 2005 2006 2007
2000
[0] J a v a \0
[1] 4000 4000 4001 4002 4003 4004 4005 4006 4007

[2] 6000 F o r t r a n \0
6000 6001 6002 6003 6004 6005 6006 6007
[3] 2010
[4] C \0
8000
2010 2011 2012 2013 2014 2015 2016 2017

Array C + + \0
indices 8000 8001 8002 8003 8004 8005 8006 8007
Use of Array of character pointers
//Use of array of character pointers for(i=0;i<4;i++)
#include<stdio.h> {
main() printf("Capital of state %d is at\t",i+1);
{ scanf("%d", &a[i]);
int i,a[4]; }
char* states[]={"Punjab", "Bihar", "Rajasthan", "Gujarat"} ; printf("-------------------------------------------\n");
char* capitals[]={"Gandhinagar", "Chandigarh", "Jaipur", for(i=0;i<4;i++)
"Patna"}; printf("%-11s is capital of %s\n", capitals[a[i]-
printf("States\t\t\tCapitals\n"); 1],states[i]);
printf("-------------------------------------------\n"); }
for(i=0;i<4;i++)
printf("%d. %-10s\t\t%d. %s\n",i+1,states[i],i+1,capitals[i]);
printf("\nMatch states in Col. 1 with capitals in Col. 2\n");
printf(“(Enter only Sr. Nos.)\n”);
printf("-------------------------------------------\n");
Output Window:
States Capitals
-------------------------------------------
1. Punjab 1. Gandhinagar
2. Bihar 2. Chandigarh
3. Rajasthan 3. Jaipur
4. Gujarat 4. Patna

Match states in Col. 1 with capitals in Col, 2


(Enter only Sr. Nos.)
-------------------------------------------
Capital of state 1 is at 2
Capital of state 2 is at 4
Capital of state 3 is at 3
Capital of state 4 is at 1
-------------------------------------------
Chandigarh is capital of Punjab
Patna is capital of Bihar
Jaipur is capital of Rajasthan
Gandhinagar is capital of Gujarat
Introduction to Structures
Arrays are used for the storage of homogeneous data.

We have user defined data types likes structures, unions, enumerations to store data with different
types

One of the similarities between arrays and structures is that both of them contain a finite number
of elements. Thus, array types and structure types are collectively known as aggregate types.

Unions are similar to structures in all aspects except the manner in which their constituent
elements are stored.

In structures, separate memory is allocated to each element, while in unions all the elements share
the same memory.

Enumerations help you in defining a data type whose objects can take a limited set of values.
STRUCTURES
A structure is a collection of variables under a single name and
provides a convenient way of grouping several pieces of related
information together.

It can be used for the storage of heterogeneous data.

Three important tasks of working with structures:

 Defining a structure type i.e. creating a new type.


 Declaring variables and constants (i.e. objects) of the newly created
type.
 Using and performing operations on the objects of the structure
type.
Defining A Structure

The general form of structure type definition is:

[storage_class_specifier][type_qualifier] struct [structure_tag_name]


{
type member_name1[, member_name11, …];
[type member_name2[, member_name22, …]];
………
} [variable_name];
Important points about structure definition:

1. The terms enclosed within the square brackets are optional and might not be present in a
structure definition statement. But the term in BOLD is mandatory.
2. A structure definition consists of the keyword struct followed by an optional identifier name,
known as structure tag-name, and a structure declaration-list enclosed within the braces.
struct book //Structure tag-name is book
{
char title [25]; //Structure declaration-list
char author[20];
int pages;
float price;
};

struct //Structure tag-name not present


{
char title[25]; //Structure declaration-list
char author[20];
int pages;
float price;
};
3. The structure definition defines a new type, known as structure type. After
the definition of the structure type, the keyword struct is used to declare its
variables.
4. Since the tag-name of a structure is an identifier, all the rules for writing an
identifier name are applicable for writing the structure tag-name.

5. The newly created type (i.e. tag name of the defined structure) is visible, after its
definition, only in the scope in which it is defined. Hence, it is not possible to
declare objects of the defined structure type outside the scope in which it (i.e. its
tag name) is visible.
6. The newly created type is incomplete until the closing brace of structure
declaration-list is encountered.
7. The structure declaration-list consists of declarations of one or more variables,
possibly of different types. The variable names declared in the structure
declaration-list are known as structure members or fields. Structure members can
be variables of the basic types (e.g. char, int, float etc.), pointer types (e.g. char*
etc.) or aggregate type (i.e. arrays or other structure types)
#include<stdio.h>
func(); //Declaration of the function func
main()
{
struct coord The type struct coord is defined in the scope local to the function
{
int x,y;
};
struct coord pt1, pt2; Declaring variables pt1 and pt2 of the created type struct
coord
//Other statements in the function main
// ………………………….
}
func()
{
struct coord pt3; //The tag name coord is not visible here
//Other statements in the function func
}
Output:
Compilation errors
8. A structure declaration-list cannot contain a member of void type
or incomplete type or function type. Hence, a structure
definition cannot contain an instance of itself. However, it
may contain a pointer to an instance of itself. Such a structure is
known as self referential structure.

9. A structure definition can have infinite number of members.


Practically it depends on the translation limits of the compiler.

10. It is possible to use the shorthand declaration to declare two or


more structure members of the same type.
struct book
{ char title [25], author[20]; //Shorthand declaration
int pages;
float price;
};
Interpretation Of Some Rules
struct record
a b c { // Structure declaration list consists of
char int float variables of different types
TYPES
char a;
(VALID)
int b;
A STRUCTURE CAN HAVE DATA OF
float c;
DIFFERENT TYPES
};
struct box
{ (INVALID)
A STRUCTURE
a b struct box a;
struct box b; CANNOT CONTAIN AN
}; INSTANCE OF ITSELF
A name consists of two names: struct name
first name and last name. { char first_name[20];
char last_name[20];
First_name Last_name }; Type struct name is complete now onwards
A phonebook entry consists of struct phonebook_entry
{
name of a person and his
struct name person_name; //Member of
mobile number.
complete type struct
Person_name mobile_no char mobile_no[10]; // name can be created.
}; (VALID)
A STRUCTURE CAN CONTAIN MEMBERS OF OTHER COMPLETE
A node of a linked list consists of TYPES
integer data and a pointer to a
struct node
node. { int data;
data ptr data ptr struct node* ptr; //instance of itself
}; (VALID)
A STRUCTURE CAN CONTAIN POINTER TO ITSELF
11. The name of a structure member can be same as the structure tag-name without any conflict, since
they can always be distinguished from the context.

12. Two different structure types may contain members of the same name without any conflict.

13. Since structure definition does not reserve any memory space for the structure members, it is not
possible to initialize the structure members during the structure definition.

struct book
{
char title [30]=”India 2020: A Vision for the new millennium ”;
char author[20]=”A P J Abdul Kalam”;
int pages=400;
float price=225.50;
};

INVALID
14. If a structure definition does not contain a structure tag-name, the created structure type is
unnamed. It is not possible to declare its objects after its definition. Thus, the objects of unnamed
structure type should be declared only at the time of structure definition.
struct
{
char title [25];
char author[20];
int pages;
float price;
} book1; //Declaration of structure variable book1
------------------------------------------------------------------------------------------------------------
const struct
{
char title [25];
char author[20];
int pages;
float price;
} book={“Programming C”, “Anirudh”, 450, 225.50};
//Creation of qualified constant book
15. A structure type definition can optionally have a storage class specifier and
type qualifiers. However, the type qualifiers and storage class specifier (except
typedef) can only be used in a structure definition if the structure objects are
also declared at the same time.
#include<stdio.h> Output:
static struct point Compilation error “Storage class ‘static’ not
{ allowed here”
int x;
int y; Remarks:
}; The storage class specifiers except typedef
main() cannot be used in a structure type definition, if
{ the objects are not declared at the time of
struct point pt1; structure definition.
//Other statements
16.} Since a structure definition is a statement, it must always be terminated with a semicolon.
THANK YOU
Online Test-6 at
https://forms.gle/PRi9pXhp7aez4Ttv8

You might also like