Lab viva guide

Python viva questions and answers (35) plus C programming viva questions (22), in spoken form

Python viva questions come after you have run your program in the Python programming lab: the examiner reads your code, asks what a line does, then asks a basic, a what-if and one deeper question. The C programming lab viva in the first year follows the same pattern with pointers and memory in place of lists and classes. This page gives 35 Python viva questions and answers and 22 C programming viva questions, each answered in the two-to-four-sentence spoken form a lab examiner wants, grouped so you can revise the section that matches your lab tonight and then say the answers out loud.

English Updated 2026-10-14 AI mock interview inside

How the Python and C lab vivas go

The programming lab practical has two halves: the program you write and execute from the list, and the five-to-ten-minute viva that follows with your record open. The internal examiner asks from the semester's experiments; the external examiner, appointed by the university for the end-semester practical, reads your record cold and asks about whatever catches the eye: a loop, a slicing expression, a pointer declaration, a line that looks copied. Viva marks are part of the practical marks under your university's scheme, and they usually separate a full score from a pass.

  • Question one is always from your own code: 'what does this line do and why did you write it that way?'
  • Question two is a basic definition from the subject: list versus tuple, pointer versus array.
  • Question three is a what-if: 'if I change this to a tuple, what happens?' or 'what if I free this pointer twice?'
  • Question four, if you are doing well, is deeper: generators, decorators, memory layout, storage classes.
  • Answer in two to four sentences, with one example from your record. Then stop and wait for the next question.

Python basics: the first questions in a Python viva

What is Python, and what are its main features?

Python is a high-level, interpreted, general-purpose language created by Guido van Rossum and released in 1991. Its main features are readable indentation-based syntax, dynamic typing, automatic memory management, a large standard library, and support for procedural, object-oriented and functional styles.

Say 'interpreted' and 'dynamically typed' clearly; the follow-up is usually 'what does dynamically typed mean?'

Say this answer out loud

Is Python compiled or interpreted?

Both, in practice. The CPython interpreter first compiles the source to bytecode, the dot pyc files, and then a virtual machine interprets that bytecode. We call it interpreted because there is no separate compile step that produces a machine-code executable like in C.

Say this answer out loud

What does dynamically typed mean?

The type belongs to the value, not the variable, and is checked at run time. So I can write x equals 5 and later x equals 'hello' without declaring a type. The cost is that type errors appear only when that line runs, not at compile time as in C.

Say this answer out loud

What is the difference between Python 2 and Python 3?

Python 3 made print a function, made integer division return a float unless you use the double slash operator, made strings Unicode by default, and changed range to return a lazy object. Python 2 reached end of life in 2020, so all lab work is in Python 3.

Say this answer out loud

Why does Python use indentation?

Indentation defines blocks instead of curly braces, so the structure you see is the structure the interpreter uses. A loop body is every line indented under the for statement. Mixing tabs and spaces or an inconsistent indent raises an IndentationError, which is the first error most of us meet in the lab.

Say this answer out loud

What are the basic data types in Python?

Numbers: int, float and complex; bool; str for text; and the collections list, tuple, set and dict. There is also NoneType for the value None. I can check any value's type with the type function, which is how I debugged a string-versus-int bug in my marks program.

Say this answer out loud

What is the difference between the slash and double-slash operators?

A single slash is true division and always returns a float, so 7 divided by 2 is 3.5. A double slash is floor division and returns the quotient rounded down, so 7 double-slash 2 is 3. The percent operator gives the remainder, 1 in this case.

Say this answer out loud

What is the difference between is and double equals?

Double equals compares values; is compares identity, whether both names point to the same object in memory. Two separate lists with the same contents are equal but not identical. I use is only for None, as in if x is None.

Say this answer out loud

What is type casting in Python?

Converting a value from one type to another with functions like int, float, str and list. For example input always returns a string, so I wrote marks equals int of input to add the numbers. Casting a non-numeric string with int raises a ValueError.

Say this answer out loud

What does the range function do?

Range produces a sequence of integers from a start up to but not including a stop, with an optional step. Range of 5 gives 0 to 4; range of 1, 10, 2 gives odd numbers under 10. It is lazy, so range of a million does not build a million-element list.

Say this answer out loud

What is the difference between break, continue and pass?

Break exits the loop entirely. Continue skips the rest of the current iteration and goes to the next one. Pass does nothing; it is an empty statement so that a block with no code is still valid syntax, for example in a function I have not written yet.

Say this answer out loud

How does Python handle memory management?

Automatically. Each object keeps a reference count, and when the count drops to zero the memory is freed immediately. A garbage collector also runs to clear reference cycles. The programmer never calls malloc or free, which is a main difference from C.

Say this answer out loud

Lists, tuples, dictionaries and strings

What is the difference between a list and a tuple?

A list is mutable: I can append, remove and change items, and it uses square brackets. A tuple is immutable, uses parentheses, is slightly faster and can be a dictionary key. I used a tuple for a fixed coordinate pair and a list for marks that change.

Say this answer out loud

What are mutable and immutable objects? Give examples.

A mutable object can be changed in place after creation: lists, dictionaries and sets. An immutable object cannot: integers, floats, strings and tuples. When I append to a list, the same object changes; when I add to a string, Python creates a new string object.

Say this answer out loud

What is a dictionary, and when do you use one?

A dictionary stores key-value pairs with unique, immutable keys and gives constant-time lookup by key. I used it in the student records program with roll number as the key and a list of marks as the value, which is far faster than searching a list of lists.

Say this answer out loud

What is the difference between a set and a list?

A set is an unordered collection of unique items with fast membership testing, while a list is ordered and allows duplicates. Converting a list to a set removes duplicates in one line. Sets also support union, intersection and difference with operators.

Say this answer out loud

What is slicing?

Slicing extracts a part of a sequence with start, stop and step in square brackets, where stop is excluded. s of 1 colon 4 gives characters 1 to 3; s of colon colon minus 1 reverses a string. It works on lists, tuples and strings and never raises an error for out-of-range indices.

Say this answer out loud

What is negative indexing?

Counting from the end: index minus 1 is the last item, minus 2 the second last. It is a cleaner way to write list of len minus 1. I used marks of minus 1 to read the latest entry in my attendance program.

Say this answer out loud

What is a list comprehension?

A one-line way to build a list from an iterable with an optional condition: squares equals x times x for x in range 10 if x percent 2 equals 0. It replaces a three-line for loop with append and is usually faster. Dictionary and set comprehensions work the same way.

Say this answer out loud

What is the difference between append and extend?

Append adds its argument as a single item, so appending a list gives a nested list. Extend adds each element of the argument individually. Appending 4, 5 as a list to 1, 2, 3 gives four items; extending gives five.

Say this answer out loud

What is the difference between remove, pop and del?

Remove deletes the first item with a given value. Pop deletes by index and returns the item, defaulting to the last one. Del is a statement that deletes by index or slice and can delete the variable itself. Remove raises ValueError if the value is absent.

Say this answer out loud

Why are strings immutable, and how do you modify one?

Immutability lets strings be hashed as dictionary keys and shared safely. To change one I build a new string: slicing and concatenation, the replace method, or joining a list of characters. Assigning to s of 0 raises a TypeError.

Say this answer out loud

What is the difference between a shallow copy and a deep copy?

A shallow copy, from the copy method or the slice colon, makes a new outer list but the inner objects are shared, so changing a nested list changes both. A deep copy from copy dot deepcopy duplicates everything recursively. Plain assignment copies nothing; it just adds a second name.

Say this answer out loud

Functions, OOP, exceptions and files

How do you define a function, and what is the difference between arguments and parameters?

With the def keyword, a name, parameters in parentheses and an indented body, returning a value with return. Parameters are the names in the definition; arguments are the actual values passed in the call. A function without return gives None.

Say this answer out loud

What are star args and double-star kwargs?

They let a function accept any number of arguments. Star args collects extra positional arguments into a tuple; double-star kwargs collects extra keyword arguments into a dictionary. I used star args in a function that averaged any number of marks.

Say this answer out loud

What is a lambda function?

An anonymous one-expression function written inline: lambda x colon x times 2. It is used where a small function is needed briefly, such as the key argument of sorted to sort students by marks. For anything longer than one expression I write a normal def.

Say this answer out loud

What is the difference between local and global variables?

A variable assigned inside a function is local to that function and disappears when it returns; one assigned at the top level is global. A function can read a global, but to assign to it I must declare global name inside the function, which I avoid because it makes bugs hard to trace.

Say this answer out loud

What is a generator?

A function that uses yield instead of return, so it produces values one at a time and remembers its state between calls. It saves memory for large sequences because nothing is stored in a list. Range and file iteration behave like generators.

Say this answer out loud

What is a decorator?

A function that takes another function and returns a modified version of it, applied with the at symbol above the definition. A common use is timing or logging a function without changing its body. In Flask, at app dot route is a decorator that registers a view function.

Say this answer out loud

What is a class, and what is the init method?

A class is a blueprint for objects, holding data attributes and methods. Init is the constructor, called automatically when an object is created, and it sets the initial attributes through self. In my library program the Book class's init stored the title, author and availability.

Say this answer out loud

What is self in Python?

Self is the first parameter of every instance method and refers to the object the method is called on. It is how a method reaches that object's own attributes, as in self dot title. The name self is a convention, not a keyword, but everyone uses it.

Say this answer out loud

What is inheritance, and what does super do?

Inheritance lets a class reuse and extend another: class Student in parentheses Person gets Person's methods. Super calls the parent's method, usually super dot init inside the child's init so the parent attributes are set too. Python also supports multiple inheritance.

Say this answer out loud

What are the four pillars of OOP, in one sentence each?

Encapsulation bundles data and methods in a class and hides internals, by convention with an underscore prefix. Abstraction exposes only what a user needs. Inheritance reuses a parent class. Polymorphism lets one method name behave differently in different classes, like len on strings and lists.

Say this answer out loud

How does exception handling work in Python?

Code that may fail goes in a try block, except blocks catch specific exceptions like ValueError or ZeroDivisionError, else runs if nothing failed, and finally runs always, for cleanup like closing a file. I raise my own exceptions with the raise statement.

Say this answer out loud

How do you read and write a file, and why use with?

Open the file with open and a mode, r for reading, w for writing, a for appending, then read, readline or write. The with statement closes the file automatically even if an error occurs, so I never leave a file open and never need to call close myself.

Say this answer out loud

C programming viva questions: basics and control flow

What is C, and why is it still taught first?

C is a procedural, compiled, middle-level language developed by Dennis Ritchie at Bell Labs in the early 1970s. It is taught first because it exposes how memory, pointers and the compiler actually work, and because operating systems, embedded firmware and the interpreters of languages like Python are written in it.

Say this answer out loud

What does the include directive do, and what is stdio dot h?

The include directive is handled by the preprocessor before compilation and pastes the contents of a header file into the program. stdio dot h is the standard input-output header that declares printf, scanf and the file functions. Without it the compiler does not know printf's signature.

Say this answer out loud

What are the steps from a C source file to a running program?

Four stages: the preprocessor handles includes and macros; the compiler turns the C into assembly and then object code; the linker joins the object file with library code such as printf into one executable; the loader puts it in memory and starts main.

Say this answer out loud

What is the difference between a declaration and a definition?

A declaration tells the compiler a name's type without allocating storage, like a function prototype or extern int count. A definition allocates storage or provides the body, like int count equals 0 or the function with its braces. A variable can be declared many times but defined once.

Say this answer out loud

What are the basic data types in C and their typical sizes?

int, char, float and double, with modifiers short, long, signed and unsigned. On a typical 64-bit Linux system char is 1 byte, int 4, float 4, double 8 and long 8. The sizes are compiler and platform dependent, which is why I use the sizeof operator instead of assuming.

Say this answer out loud

What is the difference between the equals and double-equals operators?

A single equals assigns a value; double equals compares two values and returns 1 or 0. Writing if x equals 5 by mistake assigns 5 to x and the condition is always true. The compiler usually only warns, so this bug reaches the lab exam often.

Say this answer out loud

What is the difference between while, do-while and for loops?

A while loop checks the condition before each iteration and may run zero times. A do-while checks after, so it always runs at least once, which suits a menu program. A for loop packs the initialisation, condition and increment into one line and is used when the count is known.

Say this answer out loud

What is the difference between break and continue?

Break leaves the innermost loop or switch immediately. Continue skips the rest of this iteration and jumps to the loop's condition or increment. In a switch statement a missing break causes fall-through into the next case, which is a classic viva what-if.

Say this answer out loud

What is the difference between printf and scanf, and why does scanf need an ampersand?

printf writes formatted output; scanf reads formatted input. scanf needs the address of the variable, written with an ampersand, so that it can store the value there; an array name is already an address so a string needs no ampersand. A missing ampersand gives a crash or garbage.

Say this answer out loud

What is a function prototype and why is it needed?

A prototype declares a function's return type and parameter types before it is used, like int add of int, int semicolon. It lets the compiler check calls when the definition comes after main or in another file. Without one the compiler may assume the wrong types.

Say this answer out loud

What is the difference between call by value and call by reference in C?

C passes everything by value: the function gets a copy, so changes do not affect the caller. To change the caller's variable I pass its address and use a pointer parameter, which is called call by reference. The swap program in the lab is the standard example.

Say this answer out loud

C viva questions: arrays, strings, pointers and memory

What is a pointer?

A pointer is a variable that stores the memory address of another variable. I declare it with an asterisk, int star p, store an address with p equals ampersand x, and read the value at that address with star p, called dereferencing. Pointers enable call by reference, dynamic memory and data structures like linked lists.

Say this answer out loud

What is a null pointer, and what is a dangling pointer?

A null pointer points to nothing; it is assigned NULL and checked before use. A dangling pointer points to memory that has been freed or has gone out of scope, so dereferencing it is undefined behaviour. After free I set the pointer to NULL to avoid it.

Say this answer out loud

What is the relationship between arrays and pointers?

An array name in most expressions decays to a pointer to its first element, so arr of i and star of arr plus i mean the same. The difference is that an array name is a constant and has sizeof equal to the whole array, while a pointer can be reassigned.

Say this answer out loud

How are strings stored in C?

As a character array ending in the null character, backslash zero. The string hello needs six bytes. Functions like strlen and printf with percent s stop at that null, so forgetting it causes reads past the end. string dot h provides strlen, strcpy, strcmp and strcat.

Say this answer out loud

What is the difference between malloc and calloc, and what does free do?

Both allocate memory on the heap at run time. malloc takes a byte count and leaves the memory uninitialised; calloc takes a count and element size and zeroes the memory. free returns the block to the heap; forgetting it causes a memory leak and freeing twice is undefined behaviour.

Say this answer out loud

What is the difference between the stack and the heap?

The stack holds local variables and function call frames; it is managed automatically and freed when the function returns, but it is small. The heap holds memory from malloc, lives until free is called, and is larger but slower and must be managed by the programmer.

Say this answer out loud

What is the difference between a structure and a union?

A structure gives each member its own storage, so its size is at least the sum of the members. A union gives all members the same storage, so its size is the largest member and only one member is valid at a time. I used a struct for a student record with roll number, name and marks.

Say this answer out loud

What are storage classes in C?

They decide a variable's scope, lifetime and default value: auto is the default for locals; static keeps its value between function calls and is initialised to zero; extern refers to a variable defined in another file; register hints to keep the variable in a CPU register.

Say this answer out loud

What is the difference between a macro and a function?

A macro, created with the define directive, is text substitution by the preprocessor, so there is no call overhead but no type checking and arguments may be evaluated twice. A function is compiled once and called at run time with type checking. For SQUARE of x plus 1, the macro gives a wrong answer without brackets.

Say this answer out loud

What is recursion, and what is the danger in it?

A function calling itself with a smaller input until a base case stops it, like factorial of n equals n times factorial of n minus 1 with factorial of 0 equals 1. The danger is a missing or wrong base case, which keeps pushing stack frames until a stack overflow.

Say this answer out loud

What is the difference between a compile-time error and a run-time error?

A compile-time error is caught by the compiler before the program runs, like a missing semicolon or an undeclared variable. A run-time error happens while running, like division by zero or a segmentation fault from a bad pointer. Logic errors are a third kind: the program runs but gives the wrong answer.

Say this answer out loud

How examiners probe in a programming viva

  • They ask you to trace: 'what is printed at the end of this loop?' Trace it slowly and aloud. A right trace said slowly beats a wrong one said fast.
  • They change the data type: list to tuple, int to char, a pointer to an array. Say what breaks and what still works.
  • They ask the cost: 'why is a dictionary faster than searching a list?' or 'why is a do-while right for a menu?'
  • They hunt for copied lines. Any line with a construct the class never used, a decorator, a ternary, a bitwise shift, gets asked. Either understand it or remove it before the exam.
  • They ask for the error you got. 'What error did this program give you first, and how did you fix it?' is a trust question. Name the real error: IndentationError, segmentation fault, ValueError.

Saying 'I don't know' in a programming viva

If you do not know the definition, offer the behaviour: 'Sir, I am not sure of the exact term, but in my program this line stopped the loop when the roll number matched.' If the examiner asks about something you never used, say so plainly: 'We did not cover decorators in the lab, but I understand it is a function that wraps another function.' Honest, short, and then quiet. Bluffing a C pointer answer is the fastest way to lose the next three questions.

What the ExamPilot AI examiner checks when you practise

In a CS/IT lab viva session on ExamPilot you name the program you wrote, say the Python student-records program or the C linked list, and the AI examiner runs a twelve-minute viva: a line from your program, a basic, a what-if, one deeper question and a trace. It interrupts when you ramble and asks 'why' after every 'what', exactly like the external examiner.

  • Correctness and precise vocabulary: mutable, immutable, dereference, declaration versus definition.
  • Brevity: two to four sentences, then silence. Long answers lose marks in the transcript review.
  • Tracing accuracy: whether you reach the right output when asked to walk through a loop or a pointer expression.
  • What-if reasoning: predicting the effect of a changed type, a missing break, a freed pointer.
  • Honesty: a clean partial answer scores above a confident wrong one.
  • Fluency: fillers, restarts and pauses, since viva marks are also about how clearly you explain.

Start with the CS/IT lab viva mock. The same examiner covers HTML and CSS viva questions for the web technology lab and DBMS and operating system viva questions for the systems labs. For the pattern behind every viva, read the engineering viva questions hub.

The night before the programming lab exam

  1. 1

    Re-run every program in the record

    Read each one line by line and mark the lines you cannot explain. Those are the examiner's first questions. Remove or learn any construct you copied.

  2. 2

    Say the ten basics without reading

    Python: interpreted, list versus tuple, mutable versus immutable, dictionary, slicing, self and init, exceptions. C: compile steps, declaration versus definition, pointers, strings, malloc and free, struct versus union.

  3. 3

    Do three traces aloud

    Pick a loop, a recursive function and a pointer or slicing expression from your record, and say the output step by step. Check it by running the program.

  4. 4

    Run one spoken mock

    Twelve minutes with the AI examiner on the lab you are sitting tomorrow. Read the transcript, cut your long answers down, and revise the two questions you missed in the morning.

If these questions are coming in a campus placement technical round rather than a lab, the same answers work but the interviewer will add a coding problem; pair this page with interview questions and answers for freshers and the Coding and Software Interview Prep course. For the final-year project defence, see final-year project viva questions.

Practise out loud

Practise your Python or C viva out loud

The AI examiner asks about the program you wrote, makes you trace a loop, tests a what-if on types or pointers, and scores correctness, brevity and honesty.

Engineering Viva · CS / IT lab viva

Read how this interview works

Frequently asked questions

What are the most common Python viva questions?
What Python is and whether it is interpreted, list versus tuple, mutable versus immutable, what a dictionary is, slicing and negative indexing, list comprehension, how functions and arguments work, what self and init are, how try-except works, and how to read a file with with. After these, the examiner asks about the program in your record, so revise your own code first.
Are C programming viva questions asked along with Python?
In most universities they are separate labs in separate semesters, C in the first year and Python later, so each viva stays within its subject. But Python examiners often ask comparison questions, like how memory management differs from C, and placement interviewers ask both. The C section on this page covers the questions that come up in either case.
How short should a viva answer be?
Two to four sentences, twenty to forty seconds. State the concept, say what it does, give one example from your own program, then stop. If the examiner wants more, they ask a follow-up, and that follow-up is where the extra marks are. Long answers get interrupted and the interruption is what the examiner remembers.
What if the examiner asks about something not in our lab syllabus?
Say so in one sentence and give what you know: 'We did not cover generators in the lab, but I understand a generator uses yield to produce values one at a time.' Examiners sometimes ask beyond the syllabus to see the ceiling; a calm partial answer leaves a good impression. Never pretend to have used something your record does not contain.
How do I practise Python and C viva questions out loud?
Reading answers silently does not prepare you for being questioned. Run an ExamPilot CS/IT lab viva session: name the program you wrote, and the AI examiner asks about it, follows up with what-ifs and a trace, interrupts when you ramble, and gives a transcript with the questions you missed. One session the night before is enough to make these answers come out in your own words.

Official sources